--as-needed and undefined non-weak symbols

Rex Dieter rdieter at math.unl.edu
Thu Oct 26 15:31:12 UTC 2006


Ville Skyttä wrote:

> On Thu, 2006-10-26 at 09:52 -0500, Rex Dieter wrote:
>> Ville Skyttä wrote:
>> 
> 
>> > trying "gcc -lgtk foo.c" on the above fails as expected, and "gcc -lgdk
>> > -lgtk foo.c" succeeds, again as expected.  However, to my surprise,
>> > "gcc -Wl,--as-needed -lgdk -lgtk foo.c" fails:
>> 
>> Try
>> gcc -Wl,--as-needed  foo.c -lgtk -lgdk
>> or even better:
>> gcc -Wl,--as-needed  foo.c `pkg-config --libs gtk+`
>> instead.
> 
> Both succeed but neither links in libgdk, resulting in runtime symbol
> lookup errors.  But anyway, that doesn't answer my question, see the two
> last paragraphs in my original message at
>
https://www.redhat.com/archives/fedora-devel-list/2006-October/msg00724.html

Yeah, I read it, you only mentioned linking, not runtime errors. (:

Confirmed, on fc5 linking succeeds, but then it fails at runtime.
./foo: symbol lookup error: /usr/lib/libgtk-1.2.so.0: undefined symbol:
gdk_root_window

This is a possible bintutils/ld regression, this works (as expected) with no
runtime errors on rhel4.

So, in short, I see 2 bugs here:
1.  libgtk shouldn't contain undefined symbols.  The problem goes away if
this is fixed.

and possibly:

2.  binutils' handling of --as-needed is apparently only looking at the
source/object file for dependancies, and not following dependant libraries. 
It could be argued that it shouldn't have to.  See (1). (:

-- Rex




More information about the fedora-devel-list mailing list