I have two static libraries:
/usr/X11R6/lib/libX11.a - Standard library, ~ 1.5MB
./libxbgi.a - Created by me, ~60KB
Now I use the following commands to compile a program, test.c: $gcc -o test test.c -lm -L /usr/X11R6/lib -lX11 -L . -lxbgi
This works fine, the executable test is 33KB, which is as expected.
If I change the order of linker inputs: $gcc -o test test.c -lm -L . -lxbgi -L /usr/X11R6/lib -lX11
the result is exactly the same as before.
Now I copied libX11.a to the current directory and tried to compile the same program: $gcc -o test test.c -lm -L . -lxbgi -lX11
It compiles, but the size of output file is an ugly 822KB.
If I change the order of linker inputs: $gcc -o test test.c -lm -L . -lX11 -lxbgi
the compilation fails, I get linker errors for the functions defined in both the libraries.
Can anybody explain this behavior? Specifically, what is the difference between the first two and the last two sets of commands, when the library I'm referring to is the same?