c++ - Autoscan autoconf 生成的配置脚本无法在 C++ 代码中找到 cmath 函数

标签 c++ g++ autotools autoconf

我很困惑为什么由 autoscan 和 autoconf 生成的配置脚本告诉我它找不到函数 powsqrt在包含 cmath 的 C++ 代码中头文件。我打电话AC_CHECK_FUNCS([pow sqrt]) (返回“否”答案)。代码编译并运行得很好,没有任何错误。

C++ 代码:

#include <cmath>
...
x = sqrt(y);

配置.ac:

AC_CHECK_FUNCS([pow sqrt])

没有库检查,但我不需要链接 -lm在 cmath 的命令行上。我不确定这是否是阻碍。看起来相当简单,所以我很困惑为什么它不起作用。仅供引用,g++ 4.1.2,autoconf 2.59,RedHat EL 5.3。

最佳答案

由于您正在编译 C++ 代码,因此您应该切换 autoconf 以使用 C++ 运行其测试,例如添加

AC_LANG(C++)

在检查之前。这将使用 C++ 运行测试,但仍然仅检查相应的 C 函数是否存在。请参阅caveats here .

关于c++ - Autoscan autoconf 生成的配置脚本无法在 C++ 代码中找到 cmath 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8806540/

相关文章:

c++ - 缩小转换和初始化列表,哪个编译器是对的?

c++ - 对静态成员使用 "template<>"

c++ - 使用 map<int, Foo> 而不是 vector<Foo> 来避免指针失效

c++ - std::vector 的容量是如何确定的

c++ - 错误 : stray ‘\224’ in program after including external library

c++ - 星号不是字符常量?

makefile - 使用 GCC 和 autotools 为各个源文件设置编译标志的最佳方法是什么?

c++ - 错误 : conversion from ‘const char (*)[11]’ to non-scalar type ‘L::Entry’ requested g++ 4. 4.5

c - 使用 autotools 链接 gstreamer 插件中的外部库

c++ - Eclipse 中的源代码外构建