gpt4 book ai didi

c++ - 包含 cmath header 时 Cmake 编译错误

转载 作者:行者123 更新时间:2023-12-01 22:38:54 25 4
gpt4 key购买 nike

这是我的代码:

#include <iostream>
#include <cmath>

int main() {
std::cout << std::sqrt(4) << std::endl;
return 0;
}

MAC操作系统10.15,CMake 3.15.4

只要包含头文件cmath.h,CMake编译就会出错。

执行命令:

cmake --build /Users/xxx/Documents/Playground/test1/cmake-build-debug --target test1 -- -j 4

出现以下错误:

/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/xxx/Documents/Playground/test/cmake-build-debug --target test -- -j 4
Scanning dependencies of target test
[ 50%] Building CXX object CMakeFiles/test.dir/main.cpp.o
In file included from /Users/xxx/Documents/Playground/test/main.cpp:2:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:314:9: error: no member named 'signbit' in the global namespace
using ::signbit;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:315:9: error: no member named 'fpclassify' in the global namespace
using ::fpclassify;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:316:9: error: no member named 'isfinite' in the global namespace; did you mean 'finite'?
using ::isfinite;
~~^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/math.h:749:12: note: 'finite' declared here
extern int finite(double)
^
In file included from /Users/xxx/Documents/Playground/test/main.cpp:2:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:317:9: error: no member named 'isinf' in the global namespace
using ::isinf;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:318:9: error: no member named 'isnan' in the global namespace
using ::isnan;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:319:9: error: no member named 'isnormal' in the global namespace
using ::isnormal;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:320:7: error: no member named 'isgreater' in the global namespace; did you mean '::std::greater'?
using ::isgreater;
^~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/functional:728:29: note: '::std::greater' declared here
struct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool>
^
In file included from /Users/xxx/Documents/Playground/test/main.cpp:2:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:321:7: error: no member named 'isgreaterequal' in the global namespace; did you mean '::std::greater_equal'?
using ::isgreaterequal;
^~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/functional:757:29: note: '::std::greater_equal' declared here
struct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool>
^
In file included from /Users/xxx/Documents/Playground/test/main.cpp:2:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:322:9: error: no member named 'isless' in the global namespace
using ::isless;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:323:9: error: no member named 'islessequal' in the global namespace
using ::islessequal;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:324:9: error: no member named 'islessgreater' in the global namespace
using ::islessgreater;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:325:9: error: no member named 'isunordered' in the global namespace
using ::isunordered;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:326:9: error: no member named 'isunordered' in the global namespace
using ::isunordered;
~~^
13 errors generated.
gmake[3]: *** [CMakeFiles/test.dir/build.make:63: CMakeFiles/test.dir/main.cpp.o] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:76: CMakeFiles/test.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/test.dir/rule] Error 2
gmake: *** [Makefile:118: test] Error 2

使用 XCode 成功编译相同的代码。如果删除头文件 cmath.h 的包含,CMake 可以正常工作。但是我需要使用 cmath 中的函数,这无法解决。

最佳答案

当我尝试安装用于互联网系统的离散事件网络模拟器时,我在 ma​​cOS Catalina 10.15 上也遇到了同样的问题 ( ns-3 )

显然,我的 /usr/local/include 文件夹中有一堆奇怪的符号链接(symbolic link)。

  • 我删除了 /usr/local/include/
  • 中的所有内容
  • 重新安装 Homebrew $brew 升级

一切又恢复正常。

关于c++ - 包含 cmath header 时 Cmake 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58498532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com