最近,我正在尝试将 Apache Ant 与 g++4.8 与 -std=c++11
一起使用。 .
如果我尝试了这段代码,它就通过了。
#include <cmath>
...
sqrtf((float)100);
但是,如果我输入:
#include <cmath>
...
sqrt((float)100);
g++ 编译器将产生错误:
/usr/bin/ld: test.o: undefined reference to symbol 'sqrtf@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
添加
-lm
也无济于事。有任何想法吗?谢谢!
最佳答案
问题不在于 apache ant,在某些 Linux 发行版中,g++ 和 gcc 编译器需要“-lm”来链接 C 中的“math.h”和 C++ 中的“cmath”所包含的 cmath 库
关于ubuntu - ld : "undefined reference to symbol ' sqrtf'"error with G++ via Apache Ant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40321507/