[Bug 945927] Re: ld incorrectly gives 'undefined reference'
CF
freysoldt at mpie.de
Mon Mar 5 09:29:02 UTC 2012
Pardon?
I DID put the c file before any library, as I have clearly written in my
bug report.
I cannot see how any of the comments in the release notes or changed
link tool chain relate to my problem: I am putting an explicit -lm in
the command line, and then the linker opens that library, and it sees
the right symbols, and yet, it does not link libm, probably because
also libfoo would have used it, too, but since libfoo isn't been linked,
libm is apparently kicked out. Sorry, this is a misbehavior.
Please reconsider this issue! It breaks the AC_CHECK_LIB macro of
autoconf, as well as complex make environments where the use of certain
libraries in specific executables is difficult to predict in advance.
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to binutils in Ubuntu.
https://bugs.launchpad.net/bugs/945927
Title:
ld incorrectly gives 'undefined reference'
Status in “binutils” package in Ubuntu:
Invalid
Bug description:
I had an unexpected link problem while trying to probe libraries in a
configure script.
I am using the latest update (2012-03-03 21:00 MEZ) of kubuntu 11.10, the binutils package is 2.21.53.20110810-0ubuntu5.1
My machine is a Intel(R) Core(TM)2 Duo CPU E8400 @ 3.00GHz, but I doubt that matters.
I was able to cook the problem down to the following.
Situation:
libfoo.so needs libm, and was created with -lm (ldd shows the dependency)
libbar.so needs libm, but was not created with -lm (no ldd dependency)
My program only needs libbar.so
Problem:
gcc prog.c -L. -lbar -lfoo -lm
yields an 'undefined reference to sinh'
If I run the link with -Wl,--trace-symbol=sinh, the linker actually reports that -lm contains sinh, but fails nevertheless.
What works is
gcc prog.c -L. -lbar -lm
gcc prog.c -L. -lbar -lm -lfoo
[The example of course cries for a simple workaround by reordering the
libs, but this is a mess when you try it in the configure. So just
take the lib ordering for granted (and this configure works on dozens
of other systems). I also know that libbar isn't up to the standards -
but, in real life, I won't change the way how other packages create
their shared libs.]
Here's some simple C files to reproduce the bug
--- a.c:
#include <math.h>
double foo (double x) { return exp(x); }
---- b.c:
#include <math.h>
double bar(double x) { return sinh(x); }
---- c.c:
double bar (double);
int main ()
{
double x = bar (1.);
}
---
gcc -fPIC -c a.c
gcc -shared -fPIC a.o -o libfoo.so
gcc -fPIC -c b.c
gcc -shared -fPIC b.o -o libbar.so
gcc c.c -L. -lbar -lfoo -lm
ProblemType: Bug
DistroRelease: Ubuntu 11.10
Package: binutils 2.21.53.20110810-0ubuntu5.1
ProcVersionSignature: Ubuntu 3.0.0-16.28-generic 3.0.17
Uname: Linux 3.0.0-16-generic x86_64
ApportVersion: 1.23-0ubuntu4
Architecture: amd64
Date: Sat Mar 3 23:08:39 2012
InstallationMedia: Kubuntu 10.04.1 LTS "Lucid Lynx" - Release amd64 (20100816.2)
ProcEnviron:
LANGUAGE=
PATH=(custom, user)
LANG=de_DE.UTF-8
SHELL=/bin/tcsh
SourcePackage: binutils
UpgradeStatus: Upgraded to oneiric on 2012-02-29 (3 days ago)
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/binutils/+bug/945927/+subscriptions
More information about the foundations-bugs
mailing list