[Bug 945927] [NEW] ld incorrectly gives 'undefined reference'

CF freysoldt at mpie.de
Sat Mar 3 22:56:04 UTC 2012


Public bug reported:

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)

** Affects: binutils (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: amd64 apport-bug oneiric

-- 
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:
  New

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