I'm new to c libraries and I'm making a project where I'm not allowed to use libtool
.
I tried looking online but everything either super confusing or just how to make one with no explanation.
I have a few questions:
- Are
.a
libraries just a collection of.o
files? - What is the difference between using
ar -rc
vslibtool
? - When the linker goes to link a library does it link the whole
.a
file or just the part it needs?
CodePudding user response:
Q: Are .a libraries just a collection of .o files?
A: Basically, yes.
The object files need to be organized in a specific archive library format. The linker wouldn't be able to use the archive UNLESS it recognized that format. Hence the need for tools like "ar" and "libtool".
Q: When the linker goes to link a library does it link the whole .a file or just the part it needs?*
A: Only the object code that's actually needed is physically added to the executable image.
Q: What is the difference between using ar -rc vs libtool?
"ar" has been around since the earliest days of Unix; long before "dynamic libraries" were invented (for *nix), before Linus Torvalds ever thought of Linux, or before Gnu existed. "libtool" is a Gnu tool that supports both dynamic and static libraries, and has a number of features above and beyond basic "ar" functionality.