trinity-devel@lists.pearsoncomputing.net

Message: previous - next
Month: March 2012

Re: [trinity-devel] CMake - how to add library to build?

From: Nix <nix@...>
Date: Fri, 09 Mar 2012 20:31:31 +0000
On 9 Mar 2012, David C. Rankin outgrape:
> It is a "gcc >=4.6.2" issue.  With the new mandates from gcc, any external
> library references are now required to be explicitly designated in the linker
> string. IIRC prior to 4.6.2, simply having the library on your system and the
> compiler being able to find it was enough.

Nope. That would have been far too expensive. :) Instead, the rule was
that if one of the shared libraries you linked against (call it A)
*itself* linked against another shared library (call it B), library B
was searched in order to resolve undefined symbols in your library, and
if the symbol was found in library B, library B was automatically added
to the DT_NEEDED list of your own shared library, just as if you'd
linked against B directly.

This at-first-sight convenient behaviour turns out to be less convenient
than it might at first appear, because if library A stops linking
against library B (which it is quite within its rights to do, of
course), linking of your library would abruptly fail, even though
nothing else may have changed in the exported symbol set of library A
nor in your code. This was considered extremely ugly.

Better to follow the nice simple rule 'link against all libraries you
use symbols from.'

(I did all these changes for KDE 3 long, long ago, but forgot to
contribute them upstream. That's all blood under the bridge anyway.)

> /usr/bin/ld: CMakeFiles/ksnapshot.dir/windowgrabber.cpp.o: undefined reference
> to symbol 'XShapeQueryExtension'
> /usr/bin/ld: note: 'XShapeQueryExtension' is defined in DSO
> /usr/lib/libXext.so.6 so try adding it to the linker command line
> /usr/lib/libXext.so.6: could not read symbols: Invalid operation
> collect2: ld returned 1 exit status
>
> THIS is the important part of the error:
>
> /usr/bin/ld: note: 'XShapeQueryExtension' is defined in DSO
> /usr/lib/libXext.so.6 so try adding it to the linker command line
>
> It's gcc telling you, "I know exactly where the darn symbol is located, but I'm
> not going to use the damn thing until you put it in your linker string..."

This is the linker telling you 'I know exactly where this symbol is
located *now*, but if I started silently using it this would shoot you
in the head if the dependent library from which I got this information
stopped depending on libXext someday.'

-- 
NULL && (void)