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?
In the C programming language, a static library is a compiled object file containing all symbols required by the main program to operate (functions, variables etc.) as opposed to having to pull in separate entities. Static libraries aren't loaded by the compiler at run-time; only the executable file need be loaded.
The -static option links a program statically, in other words it does not require a dependency on dynamic libraries at runtime in order to run. To achieve static linking requires that the archive ( . a ) versions of your libraries exist on the system. so /usr/lib/libc.
Static libraries are simply a collection of ordinary object files; conventionally, static libraries end with the ``. a'' suffix. This collection is created using the ar (archiver) program. Static libraries aren't used as often as they once were, because of the advantages of shared libraries (described below).
So what is a Static library?? When linked like this the library is called a static library, because the library will remain unchanged unless the program is recompiled. This is the most straight forward way of using a library as the final result is a simple executable with no dependencies.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With