tags:

views:

99

answers:

1

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!

+3  A: 

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.

Richard Pennington
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