問題描述
從 Mojave 升級到 Catalina 后,在 env 中設置:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk.
After upgrading to Catalina from Mojave, Setuping: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk in the env.
我無法編譯使用
標頭的程序.
I'm unable to compile a program that use <cmath>
header.
我嘗試更改 CFLAGS、CCFLAGS、CXXFLAGS 以指向 MacOSSDK 位置,但沒有任何變化
I tried changing CFLAGS, CCFLAGS, CXXFLAGS to point to the MacOSSDK Location that change nothing
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
存在于全局命名空間和我的計算機上:
for example the macro: isless
is present in the global namespace and on my computer:
? 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 標頭也包含它:
Even the cmath header include it:
? 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
的價值是什么?
I'm curious: What compiler are you using? What's the value of CMAKE_OSX_SYSROOT
?
我相當確信這是錯誤的 CMAKE_OSX_SYSROOT
的結果.我在使用 python 綁定進行 clang 時遇到了您描述的問題(其中 CMake 不管理編譯器調用),但我設法通過執行以下操作在 CMake 中重新創建錯誤:
I'm fairly convinced this is the result of a wrong CMAKE_OSX_SYSROOT
. I had the problem you're describing when using python bindings for clang (where CMake doesn't manage the compiler call), but I managed to recreate the error in CMake by doing:
set(CMAKE_OSX_SYSROOT "") # Reset.
我按照這個問題的答案解決了我的問題:更新到 macOS Catalina 后無法用 C++ 代碼編譯 R 包.
I solved my problem by following the answers to this question: Cannot compile R packages with c++ code after updating to macOS Catalina.
總結:在 Catalina 上,/usr/include
被 SIP 清除和保護.因此,任何希望在那里找到 C 頭文件的項目都將無法編譯.如果我沒記錯的話,Apple 建議向希望 /usr/include
中的 C 頭文件的項目提交錯誤報告.
To summarise: On Catalina, /usr/include
is purged and protected by SIP. Thus, any project that expects the C headers to be found there will fail to compile. If I remember correctly, Apple recommends to file bug reports to projects that expect C headers in /usr/include
.
您必須將要編譯的代碼的構建系統指向正確的標頭:
You must point the build system of the code you're trying to compile to the right headers:
(1) 確保 Xcode 是最新的.不知道 Catalina 上過時的 Xcode 會對您的構建環境造成什么影響.
(1) Make sure Xcode is up to date. There's no telling what an outdated Xcode on Catalina might do to your build environment.
(2) 使用-isysroot/sdk/path
編譯器標志,其中/sdk/path
是xcrun --show-sdk-的結果路徑
.我不確定 CMake 的最佳實踐是什么,但嘗試做
(2) Use the -isysroot /sdk/path
compiler flag, where /sdk/path
is the result of xcrun --show-sdk-path
. I'm not sure what CMake's best practice is, but try doing
set(CMAKE_OSX_SYSROOT /sdk/path)
或
set(CMAKE_CXX_FLAGS "[...] -isysroot /sdk/path")
如果這解決了問題,您可能想在 CMake 中尋找更好的方法來做到這一點.
If that solves the problem, you may want to look for a better way to do this in CMake.
當然,如果你喜歡冒險,你也可以禁用 SIP,正如我的問題的答案中所建議的:/usr/include 在 macOS Catalina 上丟失(使用 Xcode 11)
Of course, if you're adventurous, you could also disable SIP, as suggested in the answer to my question: /usr/include missing on macOS Catalina (with Xcode 11)
這篇關于Catalina C++:使用 <cmath>標頭產生錯誤:全局命名空間中沒有名為“signbit"的成員的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!