gcc option "-lm" fails - cannot link agains libm

Bug #1056340 reported by Ludwig Knoblauch
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc-defaults (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

I newly installed LinuxMint13 (Mate 64 Bit) , fully updated (2012-09-25) , on a new AMD64 machine.

gcc works properly except when using mathlib functions. Error messages always indicate that sqrt() and other mathlib functions are unresolved. I checked the installation and found:

 - /usr/lib/x86_64-linux-gnu/libm.a
 - /usr/lib/x86_64-linux-gnu/libm.so ( -> /lib/x86_64-linux-gnu/libm.so.6)
 - /lib/x86_64-linux-gnu/libm.so.6 ( -> libm-2.15.so)
 - /lib/x86_64-linux-gnu/libm-2.15.so

Symbol "sqrt" was present (type "W") in both the static and the shared library.

Both "gcc -lm" and "gcc -L/usr/lib/x86_64-linux-gnu -L/lib/x86_64-linux-gnu -lm" reported persistently:
"undefined reference to sqrt".

Same picture with all other libm functions I tried. The source code contains "#include <math.h>", of course.
What is going wrong?

Revision history for this message
Ludwig Knoblauch (ludwig-knoblauch) wrote :

"-m64" didn't help, either.

Protocol of "gcc -v":

cc -v -L/usr/lib/x86_64-linux-gnu -L/lib/x86_64-linux-gnu -lm sieve1-4.o sieveMethods.o -o sieve1-4
Using built-in specs.
COLLECT_GCC=cc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-L/usr/lib/x86_64-linux-gnu' '-L/lib/x86_64-linux-gnu' '-o' 'sieve1-4' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.6/collect2 --sysroot=/ --build-id --no-add-needed --as-needed --eh-frame-hdr -m elf_x86_64 --hash-style=gnu -dynamic-linker /lib64/ld-linux-x86-64.so.2 -z relro -o sieve1-4 /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o -L/usr/lib/x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.6 -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../.. -lm sieve1-4.o sieveMethods.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/4.6/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crtn.o
sieve1-4.o: In function `main':
sieve1-4.c:(.text.startup+0x8c): undefined reference to `trunc'
sieve1-4.c:(.text.startup+0x2c4): undefined reference to `sqrt'
collect2: ld returned 1 exit status
make: *** [sieve1-4] Error 1

description: updated
Revision history for this message
Ludwig Knoblauch (ludwig-knoblauch) wrote :

Additional finding: actual reason for this behavior is the way how linker options are passed. "-lm" and similar must be added to the gcc commandline following all those ".c" and ".o". Unhappily, "make" puts the LDFLAGS too early. After all, gcc is able to link libm pretty well, but LDFLAG is not longer suitable to pass library options. So lot of old makefiles are now broken.

Revision history for this message
Christian Fechteler (christian-fechteler) wrote :

See also bug-report: #1161055
It seems to be a problem for the Ubuntu-based Mint. Under LMDE the compilation works correctly

Vlad Orlov (monsta)
affects: linuxmint → gcc-defaults (Ubuntu)
Revision history for this message
Matthias Klose (doko) wrote :

not an Ubuntu issue. please report the issue where you download the packages.

Changed in gcc-defaults (Ubuntu):
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.