mxcl
mxcl

Reputation: 26883

What does a GCC compiled static library contain?

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?

Upvotes: 7

Views: 2634

Answers (3)

Robert Gamble
Robert Gamble

Reputation: 109012

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.

Upvotes: 5

Tim Robinson
Tim Robinson

Reputation: 54734

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

Upvotes: 6

user149341
user149341

Reputation:

Just the object code for libsamplerate. Statically linking against a single library doesn't make all libraries linked statically; that would be Bad.

Upvotes: 1

Related Questions