C
Christopher Hulbert
Stephan said:You're really barking up the wrong tree here. The static libraries in
your standard gcc distribution are compiled with large linker sections,
essentially meaning the linker will bring lots of stuff into the
executable that isn't used at all. A disassembly or simple "nm" will
tell you this.
[snip]
[OT]
You are wrong: if (under UNIX, don't know about Windows) a program
is linked against static libraries (i.e., lib<X>.a) then the libraries
are used
to resolve undefined symbols of A) the object files and B) any new
undefined symbols that result from step A.
If you link object files (i.e., <X>.o) the all symbols from these
object
files are put into the binary. In this respect, shared libraries behave
like object files when loaded by the loader.
[/OT]
Regards, Stephan
Off Topic:
Just to clarify and give an example of what atgraham [I believe] is talking about.
consider two files a.c and b.c
$ cat a.c
void a1(void) { return;}
void a2(void) { return;}
#include <stdlib.h>
$ cat b.c
extern void a1(void);
int main(void)
{
a1();
}
Then,
$ gcc -c -oa.o a.c;ar r liba.a a.o
$ nm liba.a
a.o:
0000000000000000 T a1
0000000000000006 T a2
$ gcc b.c -L. -la
$ nm a.out | grep a2
000000000040047a T a2
Notice how the program compiled from b linking against liba.a used a2 despite
b.c never calling it. This is a shortcoming in the GNU linker in which it can
not perform function-level linking (i.e. extracting just the function a1 from
a.o). So for object files with many functions in it (consider the HDF 5 library
for example), this starts to add up. That is what I think he was reffering to,
or he should correct me. This is why a lot of code is written with few
functions per source file.