Linker -l and .o search order

John Graham johngavingraham@googlemail.com
Tue Sep 29 11:35:00 GMT 2009


I have a question about using g++ as a linker, and the order in which
you specify search paths.

As I understand it, g++ -lx -ly will search libx.a before liby.so.
When I'm compiling a particular application, I usually put something
like:

g++ obj.o -lmylib

to compile obj.o and link in libmylib.a, which works just dandy.
However, when I specify:

g++ -lmylib obj.o

then I get link errors about not being able to find symbols defined in
libmylib.a!  Why is this?  Is this a bug, or the intended behaviour?
Is there any way to change this behaviour on the command-line (it
would make life easer for me with an existing tool I want to use that
wants to insert my -l*'s before my *.o's)

Thanks for any info anyone can provide,

John G



More information about the Gcc-help mailing list