List Info

Thread: Order of linking libraries




Order of linking libraries
user name
2007-07-05 10:24:46


hi,

  When i try to create an exec linking with multiple libraries, does the order in which i link matter, if there are dependencies across the libs?

eg:

TEST_EXE:
                $(LN) -o TEST_EXE -l $(LIB1) $(LIB2) $(LIB3)

= Are the libs picked up from right to left or are they all extracted before being linked?       
    


rgds,
Satish

Re: Order of linking libraries
country flaguser name
Israel
2007-07-06 05:13:34
> Date: Thu, 5 Jul 2007 20:54:46 +0530
> From: "Satish S" <satish12gmail.com>
> 
>   When i try to create an exec linking with multiple
libraries, does the
> order in which i link matter, if there are dependencies
across the libs?

It depends on the linker, but with most of them, the order
does
matter.

> eg:
> 
> TEST_EXE:
>                 $(LN) -o TEST_EXE -l $(LIB1) $(LIB2)
$(LIB3)

The Make variable for the linker is $(LD), not $(LN).

> Are the libs picked up from right to left or are they
all extracted before
> being linked?

With one-pass linkers, such as GNU ld (and the other Unix
linkers),
they are scanned left to right.  GNU ld can be optionally
forced to
repeatedly rescan a group of libraries until all symbols are
resolved
(see the -( and -) options).


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

Re: Order of linking libraries
user name
2007-07-11 08:03:35
hi ,

I am having a sort of circular dependencies across libraries., with extern params on both the libs. I am linking with gcc and not ld. I belive gcc internally uses ld for linking. correct me if i am wrong.

the option -( <archive> -) did not work for gcc. Is there any other way for going around this?

-Satish

On 7/6/07, Eli Zaretskii < elizgnu.org"> elizgnu.org&gt; wrote:
> Date: Thu, 5 Jul 2007 20:54:46 +0530
> From: "Satish S" < satish12gmail.com">satish12gmail.com>
>
&gt; &nbsp; When i try to create an exec linking with multiple libraries, does the
> order in which i link matter, if there are dependencies across the libs?

It depends on the linker, but with most of them, the order does
matter.

> eg:
>
&gt; TEST_EXE:
> &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; $(LN) -o TEST_EXE -l $(LIB1) $(LIB2) $(LIB3)

The Make variable for the linker is $(LD), not $(LN).

> Are the libs picked up from right to left or are they all extracted before
>; being linked?

With one-pass linkers, such as GNU ld (and the other Unix linkers),
they are scanned left to right.&nbsp; GNU ld can be optionally forced to
repeatedly rescan a group of libraries until all symbols are resolved
(see the -( and -) options).



--
Those who cannot remember the past are condemned to repeat it - George Santayana
Re: Order of linking libraries
country flaguser name
Israel
2007-07-11 14:21:43
> Date: Wed, 11 Jul 2007 18:33:35 +0530
> From: "Satish S" <satish12gmail.com>
> 
> I am having a sort of circular dependencies across
libraries., with extern
> params on both the libs. I am linking with gcc and not
ld. I belive gcc
> internally uses ld for linking. correct me if i am
wrong.
> 
> the option -( <archive> -) did not work for gcc.
Is there any other way for
> going around this?

You need to tell GCC to pass the option to the linker:

  -Wl,-( ... -Wl,-)

(untested).


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

Re: Order of linking libraries
user name
2007-07-11 14:29:38
On 2007-07-11 18:33:35 (+0530), Satish S <satish12gmail.com> wrote:
> hi ,
> 
> I am having a sort of circular dependencies across
libraries., with extern
> params on both the libs. I am linking with gcc and not
ld. I belive gcc
> internally uses ld for linking. correct me if i am
wrong.
> 
> the option -( <archive> -) did not work for gcc.
Is there any other way for
> going around this?
> 
> -Satish
> 

Gcc is a driver program. It will figure out which program to
call to
compile/link the file. I believe it uses the file extension
(.c, .cpp,
...) to make it's decision.

It is possible to pass options to ld, even though you call
gcc. You need
-Wl,<linker option> to pass commands directly to the
linker.

You can use the -v option to see which commands the driver
issues.

Kristof


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

Re: Order of linking libraries
user name
2007-07-11 15:21:34
On 7/11/07, Satish S <satish12gmail.com> wrote:
> I am having a sort of circular dependencies across
libraries., with extern
> params on both the libs. I am linking with gcc and not
ld. I belive gcc
> internally uses ld for linking. correct me if i am
wrong.

If library A requires library B and library B requires
library A, then
why are they separate at all?  A circular dependency like
this
suggests that the division of the objects into libraries is
not on the
'natural' boundaries, which indicates that either the
concepts were
poorly split to begin with or that the implementations have,
for one
reason or another, been allowed to become completely
non-modular.
That happens, and the previously mentioned linker options
are there to
let you continue to get things done, but it should be
considered a big
warning sign that your design isn't nearly as modular as it
might
appear on paper.  Depending on the details, you should
probably either
merge the libraries completely, split the underlying objects
along
different lines, or rework the involved objects to not be
interdependent.

As for passing the options through to the linker, make sure
that you
not only use the -Wl, prefix, but also that you quote the
options so
that the parentheses are not treated as special syntax by
the shell:

    gcc -o program obj1.o obj2.o "-Wl,-(" -lA -lB
"-Wl,-)"


Philip Guenther


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

Re: Order of linking libraries
user name
2007-07-12 02:53:12
The first thing to say is that this has nothing whatever to
do with GNU
make.  For help with linking issues you should contact a
group related
to your compiler/linker toolchain; in this case GCC.

Second, if you don't want to mess with special linker flags
you can use
the tried and true method of listing the libraries multiple
times.  If
libA and libB are mutually referenced, just do something
like:

	gcc -o foo -lA -lB -lA -lB

It's remotely possible you'd need to list them more than
twice, but I've
never seen a case of this in real life.

Plus this will work with all linkers, just just the GNU
linker.

-- 
------------------------------------------------------------
-------------------
 Paul D. Smith <psmithgnu.org>          Find
some GNU make tips at:
 http://www.gnu.org        
             http://make.paulandlesl
ey.org
 "Please remain calm...I may be mad, but I am a
professional." --Mad Scientist


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

[1-7]

about | contact  Other archives ( Real Estate discussion Medical topics )