从Mojave升级到Catalina后,在环境中设置:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk。
我无法编译使用<cmath>
标头的程序。
我尝试更改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标头包括它:
➜ 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
的结果。当您对clang使用python绑定时,我遇到了您要描述的问题(其中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标头的项目。
您必须将要编译的代码的构建系统指向正确的标题:
((1)确保Xcode是最新的。没有人说过Catalina上过时的Xcode对您的构建环境有什么影响。
(2)使用-isysroot /sdk/path
编译器标志,其中/sdk/path
是xcrun --show-sdk-path
的结果。我不确定CMake的最佳做法是什么,但是请尝试>]
set(CMAKE_OSX_SYSROOT /sdk/path)
或
set (CMAKE_CXX_FLAGS "[...] -isysroot /sdk/path")
如果能够解决问题,您可能希望在CMake中寻找一种更好的方法。
当然,如果您喜欢冒险,也可以按照对我的问题的回答/usr/include missing on macOS Catalina (with Xcode 11) 中的建议,禁用SIP:>