Re: Linker -l and .o search order

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



John Graham wrote:

> 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)

The linker searches in order from right to left to satisfy symbol
dependencies; in the command you have provided, any symbols required by
'mylib' that are provided by obj.o would be satisfied, but the reverse
is not true ('mylib' will not be searched for symbols to satisfy
requirements of obj.o).

This is why you will occasionally see linker commands like this:

$ g++ -o foo foo.cpp -lalib -lblib -lalib

In this sort of case, 'alib' was specified twice because it both
provides symbols to 'blib' and requires symbols from 'blib' (a circular
symbol dependency).

-- 
Kevin P. Fleming
Digium, Inc. | Director of Software Technologies
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
skype: kpfleming | jabber: kpfleming@xxxxxxxxxx
Check us out at www.digium.com & www.asterisk.org

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux