快速数学原因未定义对__pow_finite的引用 [英] fast-math cause undefined reference to `__pow_finite'
问题描述
在ubuntu 20.04上,当我使用clang-8或clang-9(clang版本9.0.1-12)编译包含对libm的引用的简单代码时,它将失败,并显示错误对 __ pow_finite <的未定义引用"/code>"
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很好.知道这里有什么问题吗?
gcc is fine. Any idea what is wrong here?
c ++具有相同的问题:
c++ has the same problem:
#include <cmath>
int main()
{
double x=1, y=1;
x = pow(x,y);
}
修改
我实际上使用了-lm,只是忘了输入文本.如果我不添加它,这是另一个错误.
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没有此问题. godbolt 也可以.在系统或特定的Subversion上一定有问题.
F31 does not have this problem. godbolt is also fine. It must be something wrong on the system or specific subversion.
到目前为止,顺序无关紧要,所以我认为这不是 gcc会不正确包含math.h :
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'
将ld更改为collect2具有相同的问题,因此不应是ld的问题.
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
更新
它似乎与 libc更新有关.不再有 math-finite.h
,因此,当 -ffast-math
生成 __ * finite
时,它将失败.铛必须更改其行为.
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.
推荐答案
在编译时添加头文件, clang -L/home/xiaokuan/lib/glibc-2.32-install/lib -I/home/xiaokuan/lib/glibc-2.32-install/include -lm -ffast-math ac
Add header files when compiling, clang -L/home/xiaokuan/lib/glibc-2.32-install/lib -I/home/xiaokuan/lib/glibc-2.32-install/include -lm -ffast-math a.c
这篇关于快速数学原因未定义对__pow_finite的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!