Problem linking to wrong class

Ian Lance Taylor iant@google.com
Tue Apr 21 14:42:00 GMT 2009


Brian Peschel <brianp@occinc.com> writes:

> Is there an option on the linker to at least warn me it is doing this?
> I understand why it is happening now (thanks!) at least.  But I am
> worried about this same problem elsewhere.  I expect this could happen
> to me with 3rd party libraries I use.  And unless a crash happens
> (like it did in this case with my own libraries), it would be
> difficult to diagnose.

There is not.  The problem is that duplicate symbols are normal in C++
code, due to C++ vague linkage, and they are not a problem provided that
the symbols all come from the same original definition.  In other words,
if there were such a linker option, it would be useless for C++ code
because there would be so many false positives.

The gold linker has a --detect-odr-violations option which will detect
some of thse cases but not all.  It looks at the debugging information
to see whether the two symbols appear to be coming from the same
definition.  This leads to a lot of false positives if you are
optimizing, so it's really only useful when using -O0 -g, and even then
it can have false negatives.

Ian



More information about the Gcc-help mailing list