4

I noticed that when I make my application with gcc and look at the output during the linking phase, I see the following lib included twice:

/home/rb01/opt/trx-HEAD/gcc/4.2.4/lib/../lib64/libstdc++.so

And so I was just wondering if this is a problem with g++ (gcc) or if the second one is simply ignored?

Thanks!

1 Answer 1

8

If symbols in a library have already been resolved, the linker ignores them. With shared libraries, as in this case, the linker doesn't actually link anyway.

With static (.a) libraries, multiple copies on the command line can actually be useful, if not very pretty, if for example main accesses libb which accesses libc which accesses something in libb not accessed by main:

ld main.o -lb -lc -lb

is one way to get all the references resolved.

1
  • 3
    You can use -( -lb -lc -) or -start-group -lb -lc -end-group to achieve the same thing more elegantly. The grouped libraries are then iterated until no further symbols are resolved.
    – Clifford
    Feb 17, 2010 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.