on ubuntu 20.04, when I use clang-8 or clang-9 (clang version 9.0.1-12) to compile a simple code containing reference to libm, it will fail with error "undefined reference to __pow_finite
"
#include <math.h>
int main()
{
double x=1, y=1;
x = pow(x,y);
}
clang-9 -lm test.c -ffast-math
/usr/bin/ld: /tmp/test-9b1a45.o: in function `main':
test.c:(.text+0x2a): undefined reference to `__pow_finite'
readelf -Ws /lib/x86_64-linux-gnu/libm.so.6| grep pow_finite
626: 000000000002ed90 65 IFUNC GLOBAL DEFAULT 17 __pow_finite@GLIBC_2.15
gcc is fine. Any idea what is wrong here?
c++ has the same problem:
#include <cmath>
int main()
{
double x=1, y=1;
x = pow(x,y);
}
edit
I actually used -lm, I just forgot to put in the text. If I do not add it, it is another error.
$ clang-9 test.c
/usr/bin/ld: /tmp/test-3389a6.o: in function `main':
test.c:(.text+0x25): undefined reference to `pow'
$ gcc test.c
/usr/bin/ld: /tmp/cc21n4wb.o: in function `main':
test.c:(.text+0x39): undefined reference to `pow'
F31 does not have this problem. godbolt is also fine. It must be something wrong on the system or specific subversion.
So far order does not matter, so I think it is not gcc will not properly include math.h:
clang-9 test.c -ffast-math -lm
/usr/bin/ld: /tmp/test-6dfc29.o: in function `main':
test.c:(.text+0x2a): undefined reference to `__pow_finite'
clang-9 -ffast-math test.c -lm
/usr/bin/ld: /tmp/test-6754bc.o: in function `main':
test.c:(.text+0x2a): undefined reference to `__pow_finite'
change the ld to collect2 has the same problem, so it should not be ld's issue.
clang-9 -v -fuse-ld=/usr/lib/gcc/x86_64-linux-gnu/9/collect2 test.c -ffast-math -lm
update
It seems related to libc update. There is no math-finite.h
any more, so when -ffast-math
generate __*finite
it will fail. clang has to change its behaviour.
undefined reference to 'pow'
not__pow_infinate
– Midwaygcc
command with-v
. It should tell you what dirs it searches and what libm it used. Because you're using an explicit version (e.g.clang-9
), you may be getting the wrong libm [for an older/newer version]. You could also run understrace
. You may need-L
and/or-rpath
options to force linkage to the correct [version specific] libs. You can runnm
orreadelf/objdump
on the various libm files to see which define the missing__pow_infinite
symbol – Thomasinethomasonmath-finite.h
– Midway