What does a GCC compiled static library contain?
-
05-07-2019 - |
Question
My application links against libsamplerate.a. I am doing this to make distributing the final binary easier.
I am worried that perhaps the code inside the .a file depends on some other libraries I also will need to distribute.
But if it doesn't I am worried I am bloating up my application too much by including multiple copies of eg. libc.
What exactly will be inside libsamplerate.a? Just libsamperate's bytecode? Or more?
Solution
A static library is just a collection of object files. When you compile a program against a static library, the object code for the functions used by your program is copied from the library into your executable. Linking against a static library will not cause any functions outside that library to be included in your code.
OTHER TIPS
A .a file is basically just a bundle of .o files. You can demonstrate this using the ar
tool.
For instance, to display the contents of your library:
ar -t libsamplerate.a
To create a .a file from scratch:
ar -r tim.a *.txt
Just the object code for libsamplerate. Statically linking against a single library doesn't make all libraries linked statically; that would be Bad.