[Bug 1851341] Re: gcc linking fails: undefined reference to sqrt
Tim Tei
1851341 at bugs.launchpad.net
Tue Nov 5 09:03:07 UTC 2019
** Attachment added: "parameters passed to ld on ubuntu"
https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1851341/+attachment/5302953/+files/ubuntu.txt
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to gcc-defaults in Ubuntu.
https://bugs.launchpad.net/bugs/1851341
Title:
gcc linking fails: undefined reference to sqrt
Status in gcc-defaults package in Ubuntu:
New
Bug description:
The code I try to compile and link:
$ cat s.c
#include <stdio.h>
#include <math.h>
int main()
{
double n = 5.0;
printf("%f\n", sqrt(n));
}
Linking fails with gcc, gcc-7, gcc-8, gcc-9:
$ gcc -lm s.c
/usr/bin/ld: /tmp/ccBhhS0F.o: in function `main':
s.c:(.text+0x23): undefined reference to `sqrt'
collect2: error: ld returned 1 exit status
Linking succeeds with g++, clang:
$ g++ -lm s.c
$ clang -lm s.c
Tested with Ubuntu 18.04 and 19.10.
On Debian linking with gcc works fine.
The parameters passed to ld differ in Debian and Ubuntu
(see ld-parameters-ubuntu.txt vs ld-parameters-debian.txt).
The first "--as-needed" is causing the problems.
ProblemType: Bug
DistroRelease: Ubuntu 19.10
Package: gcc 4:9.2.1-3.1ubuntu1
ProcVersionSignature: Ubuntu 5.3.0-19.20-generic 5.3.1
Uname: Linux 5.3.0-19-generic x86_64
ApportVersion: 2.20.11-0ubuntu8.2
Architecture: amd64
CurrentDesktop: ubuntu:GNOME
Date: Tue Nov 5 08:46:14 2019
ProcEnviron:
LANGUAGE=de_DE:
PATH=(custom, no user)
XDG_RUNTIME_DIR=<set>
LANG=de_DE.UTF-8
SHELL=/bin/bash
SourcePackage: gcc-defaults
UpgradeStatus: Upgraded to eoan on 2019-10-29 (6 days ago)
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1851341/+subscriptions
More information about the foundations-bugs
mailing list