c++ - 卡塔琳娜 C++ : Using <cmath> headers yield error: no member named 'signbit' in the global namespace

标签 c++ macos clang toolchain macos-catalina

从 Mojave 升级到 Catalina 后,在环境中设置:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk。

我无法编译使用 <cmath> 的程序 header 。

我尝试更改 CFLAGS、CCFLAGS、CXXFLAGS 以指向 MacOSSDK 位置,但没有任何更改

Scanning dependencies of target OgreMain
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f OgreMain/CMakeFiles/OgreMain.dir/build.make OgreMain/CMakeFiles/OgreMain.dir/build
[  0%] Building CXX object OgreMain/CMakeFiles/OgreMain.dir/src/OgreASTCCodec.cpp.o
cd /Users/roman/Downloads/ogre-1.12.2/build/OgreMain && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++  -DOgreMain_EXPORTS -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=0 -I/Users/roman/Downloads/ogre-1.12.2/OgreMain/src/OSX -I/Users/roman/Downloads/ogre-1.12.2/OgreMain/include/Threading -I/Users/roman/Downloads/ogre-1.12.2/OgreMain/src -I/Users/roman/Downloads/ogre-1.12.2/build/Dependencies/include -I/Users/roman/Downloads/ogre-1.12.2/OgreMain/include -I/Users/roman/Downloads/ogre-1.12.2/build/include -I/Users/roman/Downloads/ogre-1.12.2/OgreMain -isystem /usr/local/include  -Wall -Winit-self -Wcast-qual -Wwrite-strings -Wextra -Wundef -Wmissing-declarations -Wno-unused-parameter -Wshadow -Wno-missing-field-initializers -Wno-long-long -Wno-inconsistent-missing-override  -msse -O3 -DNDEBUG -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -fPIC -fvisibility=hidden -fvisibility-inlines-hidden   -std=c++11 -o CMakeFiles/OgreMain.dir/src/OgreASTCCodec.cpp.o -c /Users/roman/Downloads/ogre-1.12.2/OgreMain/src/OgreASTCCodec.cpp
In file included from /Users/roman/Downloads/ogre-1.12.2/OgreMain/src/OgreASTCCodec.cpp:29:
In file included from /Users/roman/Downloads/ogre-1.12.2/OgreMain/src/OgreStableHeaders.h:40:
In file included from /Users/roman/Downloads/ogre-1.12.2/OgreMain/include/OgrePrerequisites.h:309:
In file included from /Users/roman/Downloads/ogre-1.12.2/OgreMain/include/OgreStdHeaders.h:10:
/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;

例如宏:isless存在于全局命名空间和我的计算机上:

➜ cat math.h | grep "isless"

#define isless(x, y) __builtin_isless((x),(y))
#define islessequal(x, y) __builtin_islessequal((x),(y))
#define islessgreater(x, y) __builtin_islessgreater((x),(y))
➜  pwd
/usr/local/include
➜

甚至 cmath header 也包含它:

➜ cat /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath | grep "math.h"
#include <math.h>

我的命令行有选项 -isystem /usr/local/include

这应该有效...

最佳答案

我很好奇:你使用什么编译器? CMAKE_OSX_SYSROOT 的值是多少?

我相当确信这是 CMAKE_OSX_SYSROOT 错误的结果。我在使用 python 绑定(bind)进行 clang 时遇到了您所描述的问题(其中 CMake 不管理编译器调用),但我设法通过执行以下操作在 CMake 中重新创建错误:

set(CMAKE_OSX_SYSROOT "")  # Reset.

我通过遵循此问题的答案解决了我的问题:Cannot compile R packages with c++ code after updating to macOS Catalina .

总结一下:在 Catalina 上,/usr/include 已被清除并受 SIP 保护。因此,任何期望在那里找到 C 头文件的项目都将无法编译。如果我没记错的话,Apple 建议向在 /usr/include 中需要 C header 的项目提交错误报告。

您必须将尝试编译的代码的构建系统指向正确的 header :

(1) 确保 Xcode 是最新的。无法确定 Catalina 上过时的 Xcode 可能会对您的构建环境造成什么影响。

(2) 使用 -isysroot/sdk/path 编译器标志,其中 /sdk/pathxcrun --show-sdk- 的结果路径。我不确定 CMake 的最佳实践是什么,但请尝试这样做

set(CMAKE_OSX_SYSROOT /sdk/path)

set(CMAKE_CXX_FLAGS "[...] -isysroot /sdk/path")

如果这解决了问题,您可能想在 CMake 中寻找更好的方法来执行此操作。

当然,如果您喜欢冒险,您也可以禁用 SIP,如我的问题的答案中所建议的:/usr/include missing on macOS Catalina (with Xcode 11)

关于c++ - 卡塔琳娜 C++ : Using <cmath> headers yield error: no member named 'signbit' in the global namespace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58628377/

相关文章:

c++ - 在 macOS 上的 CLion 中导入 Bazel 项目失败

c++ - WSI 同步子 channel 依赖和链接到颜色附件输出

c++ - 向菜单项添加工具提示)

c++ - 使用 Visual Studio C++ 20 导入公共(public)模块文件夹的最佳方法

objective-c - 如何让 "Select All"在我的子类 NSTextField/NSTextFieldCell 中工作?

macos - 尝试在 Mac OSX 10.6.8 上安装 PEAR

c++ - 从 clang 中的 FunctionDecl 类获取参数信息

windows-phone-8 - 针对 Windows Phone ARM 目标的 Clang 交叉编译

c++ - CGAL 库 Vertex_visibility_graph_2.h 的问题

c++ - vector::clear 在 libc++ 中用于简单可破坏的类型