Inheritance & linking... found!

Andrea Pippa ingpippa at
Sun Jul 7 21:26:07 UTC 2002

Hi! I've found the problem !

Simply, ld treats archives and objects in this way: they are processed
as they are given in the command line, in the same order; every time ld
encounters an archive, adds from it only the objects that are needed by
the time the archive is encountered, so if some archive after that needs
symbols from the first, they are lost. Example:

liba.a contains base.o that defines base::base()
libb.a contains child.o that defines child::child() that needs
main.o defines main() that needs child::child()

ld -o test main.o libb.a liba.a                will work.

ld -o test main.o liba.a libb.a                 won't work:

infact, when ld encounters liba.a, base::base() is not needed by already
processed objects (main.o), so base.o from liba.a is not included. Then,
from libb.a is included child.o (since main.o requires it), but there is
child::child() that needs base::base(), that was in base.o in liba.a,
that was not included. So, linking error!

To fix that, there are 2 ways:

- easy way:     use --start-group  ...put all archives here...
    Those group all archives, so they are processed in a loop until no
new objects are included.

- hard way:     do topological sort on the dependency graph, so have an
order that avoid inconsistences like the one above, and use the
--start-group --end-group only limited to unavoidable circular
dependencies (that should be quite rare: something like a class A in lib
A that need a class B in lib B, and a class C in lib B that need a class
D in lib A).

That is...



to unsubscribe from this list send an email to kdevelop-request at with the following body:
unsubscribe »your-email-address«

More information about the KDevelop mailing list