[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug ld/14773] New: ld --as-needed reports undefined reference in the wr
From: |
ats-sourceware at offog dot org |
Subject: |
[Bug ld/14773] New: ld --as-needed reports undefined reference in the wrong library |
Date: |
Sat, 27 Oct 2012 14:41:50 +0000 |
http://sourceware.org/bugzilla/show_bug.cgi?id=14773
Bug #: 14773
Summary: ld --as-needed reports undefined reference in the
wrong library
Product: binutils
Version: 2.23
Status: NEW
Severity: minor
Priority: P2
Component: ld
AssignedTo: address@hidden
ReportedBy: address@hidden
Classification: Unclassified
Host: x86_64-unknown-linux-gnu
Target: x86_64-unknown-linux-gnu
Build: x86_64-unknown-linux-gnu
Created attachment 6702
--> http://sourceware.org/bugzilla/attachment.cgi?id=6702
Script to reproduce the problem
If I have:
- libshared.so linked with -lX11, containing func which calls XFillRectangle
- libstatic.a, containing func2 which calls XFillRectangle
- main.o, containing main which calls func and func2
... and I do:
gcc -Wl,--as-needed -o main main.o libshared.so -lX11 libstatic.a
... then I get an error like this:
/gar/bin/ld: libshared.so: undefined reference to symbol 'XFillRectangle'
/gar/bin/ld: note: 'XFillRectangle' is defined in DSO /lib64/libX11.so so try
adding it to the linker command line
/lib64/libX11.so: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
The "undefined reference" report is misleading -- XFillRectangle isn't an
undefined symbol in libshared.so, because libshared.so was correctly linked
against -lX11. It's an undefined symbol in libstatic.a.
This happens for me with binutils 2.23 and 2.22 built from source, and with
Debian wheezy's 2.22. I'll attach the output from all three of these, but it's
effectively the same, just with different paths.
I actually ran into this problem while building motif 2.3.4, where the static
library was libExm.a, the shared library was libXm.so, and the executable being
linked was simple_app.
Interestingly, if you remove the -lX11 from the ld invocation, then it links
quite happily -- which I didn't expect with --as-needed...
Let me know if you need any more details -- thanks!
--
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
- [Bug ld/14773] New: ld --as-needed reports undefined reference in the wrong library,
ats-sourceware at offog dot org <=