[Top][All Lists]

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

Re: Order of linking libraries

From: Philip Guenther
Subject: Re: Order of linking libraries
Date: Wed, 11 Jul 2007 14:21:34 -0600

On 7/11/07, Satish S <address@hidden> 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

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

reply via email to

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