fast-math导致未定义对`__pow_finite'的引用。

问题描述 投票:0回答:1

在ubuntu 20.04上,当我使用clang-8或clang-9(clang版本9.0.1-12)编译一个包含对libm的引用的简单代码时,它会以 "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是好的。知道是什么问题吗?

c++也有同样的问题。

#include <cmath>

int main()
{
    double x=1, y=1;
    x = pow(x,y);
}

编辑

其实我用的是-lm,只是忘了加文字。如果我不加,又是一个错误。

$ 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 也是好的。一定是系统上出了问题,或者是特定的颠覆。

到目前为止,顺序并不重要,所以我认为这不是 gcc不能正确地包含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的问题。

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 会失败的,Clang必须 改头换面.

c++ c clang clang++ ubuntu-20.04
1个回答
-1
投票

似乎你没有链接一些你应该链接的东西。

从注释来看,似乎你需要的标志是 -lm 以获得数学库。

clang-9 test.c -lm -ffast-math
© www.soinside.com 2019 - 2024. All rights reserved.