Static Library

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Typan
Posts: 17
Joined: Mon Sep 29, 2025 10:12 am
Libera.chat IRC: Typan

Static Library

Post by Typan »

Hello,

I am working on a custom operating system and I want create static libraries. I am working on a MacBook M4 (silicon).

I am using the compiler x86_64-elf-gcc and linker x86_64-elf-ld. The problem is when I create a static library with command:

ar -r libc.a *.o I get a library. But if I am using command ranlib I get response:

warning: /Library/Developer/CommandLineTools/usr/bin/ranlib: archive library: libc.a the table of contents is empty (no object file members in the library define global symbols)

And the library is not working with the linker.

Does anybody know what is wrong?

Kind regards,
Robert
klange
Member
Member
Posts: 696
Joined: Wed Mar 30, 2011 12:31 am
Libera.chat IRC: klange
Discord: klange

Re: Static Library

Post by klange »

You need to use the ar and ranlib that came with your linker, which should exist with the same prefix, eg. x86_64-elf-ar and x86_64-elf-ranlib. The unprefixed ones you are using on macOS are part of a mach-o toolchain and do not understand your ELF object files.
Typan
Posts: 17
Joined: Mon Sep 29, 2025 10:12 am
Libera.chat IRC: Typan

Re: Static Library

Post by Typan »

Hi klange,

Thank you so much for this answer and it is working :-)

Kind regards,
Robert
Post Reply