[Top][All Lists]

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

Re: Libs ordering in LDADD

From: Eric Siegerman
Subject: Re: Libs ordering in LDADD
Date: Mon, 20 Oct 2003 17:10:26 -0400
User-agent: Mutt/1.2.5i

On Sun, Oct 19, 2003 at 12:07:37PM -0400, Earnie Boyd wrote:
> the line order.  If I have object foo that has dependency to libbar.a 
> then I must have object foo before -lbar.

To explain why that is:  when the linker searches a library, it
only links in the modules that it knows to be needed.  Suppose
foo.o needs function bazzle(), which is found in -lbar.  If you
        ld .... -lbar foo.o
Then at the time the "bar" library is searched, the linker
doesn't yet know that bazzle() is needed, and so doesn't link it
in.  Then foo.o comes along with a reference to undefined
function bazzle(), but nothing *following* foo.o on the command
line can satisfy that reference.  You get an "undefined" error.
But with:
        ld .... foo.o -lbar
the linker knows, while searching -lbar, that it needs bazzle().

The situation with two libraries is similar.


|  | /\
|-_|/  >   Eric Siegerman, Toronto, Ont.        address@hidden
|  |  /
When I came back around from the dark side, there in front of me would
be the landing area where the crew was, and the Earth, all in the view
of my window. I couldn't help but think that there in front of me was
all of humanity, except me.
        - Michael Collins, Apollo 11 Command Module Pilot

reply via email to

[Prev in Thread] Current Thread [Next in Thread]