从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
这应该有效...
答案 0 :(得分:13)
在尝试定位iOS(在MacBook Air和GitHub Actions运行器上)时,我遇到了相同的问题,即使我对Apple的生态系统不够熟悉,也无法解决这个问题。适当的解决方案。最初的命令行来自cpprestsdk中的CMake,但是一旦我将其归结为基本知识,这里便是一个简短的副本。
cmath-bug.cpp
,其中只有一行: #include <cmath>
clang -v -x c++ -target arm64-apple-ios13.2 -fcolor-diagnostics -std=c++11 -stdlib=libc++
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk
-isystem /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/include
-c cmath-bug.cpp
运行它时,我会遇到许多面临相同问题的人:
Apple clang version 11.0.0 (clang-1100.0.33.16)
Target: arm64-apple-ios13.2
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple arm64-apple-ios13.2.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name cmath-bug.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=13.2 -target-cpu cyclone -target-feature +fp-armv8 -target-feature +neon -target-feature +crypto -target-feature +zcm -target-feature +zcz -target-feature +sha2 -target-feature +aes -target-abi darwinpcs -fallow-half-arguments-and-returns -dwarf-column-info -debugger-tuning=lldb -ggnu-pubnames -target-linker-version 530 -v -coverage-notes-file /Users/myuser/Projects/C++/cmath-bug.gcno -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk -isystem /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/include -stdlib=libc++ -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1 -Wno-framework-include-private-from-public -Wno-atimport-in-framework-header -Wno-extra-semi-stmt -Wno-quoted-include-in-framework-header -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/myuser/Projects/C++ -ferror-limit 19 -fmessage-length 204 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=ios-13.2.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o cmath-bug.o -x c++ cmath-bug.cpp
clang -cc1 version 11.0.0 (clang-1100.0.33.16) default target x86_64-apple-darwin19.0.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/Library/Frameworks"
ignoring duplicate directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/System/Library/Frameworks (framework directory)
End of search list.
In file included from cmath-bug.cpp:1:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:318: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:319: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:320:9: error: no member named 'isfinite' in the global namespace; did you mean 'finite'?
using ::isfinite;
~~^
我在原始命令行中传递的仅有两个include目录存在并且是:
$ ls -alF /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk
lrwxr-xr-x 1 root wheel 12B Dec 17 11:54 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk@ -> iPhoneOS.sdk
$ ls -alF /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/include
total 2160
drwxr-xr-x 169 root wheel 5.3K Dec 17 12:07 ./
drwxr-xr-x 5 root wheel 160B Nov 4 19:22 ../
...
-rw-r--r-- 9 root wheel 32K Nov 4 19:52 math.h
...
但是这里有趣的是它报告的不存在的include目录以及最终搜索到的include目录及其顺序。我的猜测是,Apple Clang的驱动程序会根据某些Apple特定的逻辑插入命令行中未提及的其他目录。
从报告的错误中您可以看到在<cmath>
处发现了/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath
标头,并且在其中的第304行可以看到:
#include <__config> // Line 304
#include <math.h> // This one ends up causing troubles
#include <__cxx_version>
从以下事实来看,在同一文件夹/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/
中有一个文件math.h
提供了必要的定义,例如:
#include <__config>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#include_next <math.h>
#ifdef __cplusplus
// We support including .h headers inside 'extern "C"' contexts, so switch
// back to C++ linkage before including these C++ headers.
extern "C++" {
#include <type_traits>
#include <limits>
// signbit
#ifdef signbit
template <class _A1>
_LIBCPP_INLINE_VISIBILITY
bool
__libcpp_signbit(_A1 __lcpp_x) _NOEXCEPT
{
return signbit(__lcpp_x);
}
#undef signbit
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
signbit(_A1 __lcpp_x) _NOEXCEPT
{
return __libcpp_signbit((typename std::__promote<_A1>::type)__lcpp_x);
}
...
#elif defined(_LIBCPP_MSVCRT)
...
#endif // signbit
<cmath>
的作者希望首先包含同一文件夹中的math.h
,然后#include_next <math.h>
伪指令找到系统特定的math.h
。但是,事实并非如此。
如果您查看搜索目录中的前2个条目:
#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
您看到特定于系统的include目录最终位于通过Clang注入的标准库目录的上方,这就是为什么找到特定于系统的math.h
的原因,而不是与其余部分位于同一文件夹中的原因标准库头。可能是这种情况,因为如果我在其他两个目录-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
之前,将标准库的include目录显式添加到命令行中,问题就会消失,并且我可以编译该文件。那不是Clang的驱动程序或此处涉及的其他任何事情自动执行的操作:它通过-internal-system
添加该标准库目录(不确定该内部标志的语义是什么),并且在系统目录之后将其添加。
现在,如果您查看被忽略目录的列表,则该列表中的第一项是:
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/usr/include/c++/v1"
其后部c++/v1
在我的计算机上不存在,这使我想知道iPhone SDK安装是否应该在指向路径的现有部分内创建符号链接c++
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++
目录使整个工作正常。
无论如何,这是我认为正在发生的事情,我想知道是否有人知道如何正确解决此问题?
谢谢!
P.S。对于上下文:
$ xcode-select -p
/Applications/Xcode.app/Contents/Developer
$ xcrun --show-sdk-path -sdk iphoneos13.2
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk
答案 1 :(得分:6)
使用命令:
gcc -Wp,-v -E -
我的#include <...>搜索顺序:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.1/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks (framework directory)
#include错误的原因如下:
#include<cmath>
驻留在/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
<math.h>
。/usr/local/include
目录,因为这是要搜索的第一个目录。 math.h
目录中有一个/usr/local/include/c++/9.3.0/
math.h
的{{1}} /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
的{{1}}使用math.h
包含/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
的{{1}} math.h
被包含/链接到/usr/local/include
,发生了编译错误解决方法:
如果我们可以将#include_next<math.h>
的搜索顺序更改为首先搜索math.h
,则可以将其固定。
在/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath
中使用#include<...>
代替/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
我遵循了#2选项,现在构建成功!
感谢solodon的详细回答。我按照答案解决了这个问题。
答案 2 :(得分:3)
我很好奇:您使用的是哪个编译器? CMAKE_OSX_SYSROOT
的值是什么?
我相当确信这是错误的CMAKE_OSX_SYSROOT
的结果。我在使用python绑定作为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标头的项目。
您必须将要编译的代码的构建系统指向正确的标题:
(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。答案 3 :(得分:2)
您的Xcode副本可能已损坏。用代码签名检查:
codesign --verify /Applications/Xcode.app
这发生在我身上,并且问题已损坏Xcode。重新安装修复它。
某些地方修改了以下内容:
file added: /Applications/Xcode-11.3.1-.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/json/__pycache__/scanner.cpython-37.pyc
file added: /Applications/Xcode-11.3.1-.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/json/__pycache__/decoder.cpython-37.pyc
file added: /Applications/Xcode-11.3.1-.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/json/__pycache__/encoder.cpython-37.pyc
file added: /Applications/Xcode-11.3.1-.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/json/__pycache__/__init__.cpython-37.pyc
file modified: /Applications/Xcode-11.3.1-.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/math.h
file modified: /Applications/Xcode-11.3.1-.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/math.h
file modified: /Applications/Xcode-11.3.1-.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/math.h
file modified: /Applications/Xcode-11.3.1-.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/math.h
file modified: /Applications/Xcode-11.3.1-.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/math.h
file modified: /Applications/Xcode-11.3.1-.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk/System/DriverKit/usr/include/math.h
file modified: /Applications/Xcode-11.3.1-.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/math.h
file modified: /Applications/Xcode-11.3.1-.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/math.h
file modified: /Applications/Xcode-11.3.1-.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/math.h
math.h
在上述所有地方都是空的。
答案 4 :(得分:2)
最近升级到10.15.4和Xcode 11.4后,尝试编译gRPC时遇到了这个错误,我开始查看提供的所有解决方案(此处和Can't compile a C program on a Mac after upgrading to Catalina 10.15),并尝试了其中的一些解决方案(尽管不尝试重新创建function singlePushArray(array,input){
//This function ADDS ONE ITEM to the END OF THE ARRAY
console.time();
console.log("This is the Output from the Single Push Array Function- Adding a Single Items to the END of the ARRAY")
console.log("This is the Original Copy of the Array: ", array);
array.push(input);//This is the function
console.log("This is the Ammended Cop of the Array: ", array);
console.timeEnd();
}
function doublePushArray(array,input1,input2){
//This function ADDS TWO Items to the END OF THE ARRAY
console.time();
console.log("This is the Output from the Double Push Array Function - Adding TWO Items to the END OF THE ARRAY");
console.log("This is the Original Copy of the Array: ", array);
array.push(input1,input2);//This is the function
console.log("This is the ammended Copy of the Array: ", array);
console.timeEnd()
}
,因为那样会违反Apple试图创建的分隔)-似乎没有任何效果。
然后,我仔细查看了/usr/include
进程正在产生的实际编译器调用,并注意到其中存在一个明确的
make
这最终导致包含以错误的顺序发生-删除此显式包含路径允许编译成功并使用默认安装的catalina,Xcode和Xcode命令行工具,正如您所期望的,没有其他技巧/ compiler标志。
答案 5 :(得分:2)
您可以尝试使用CommandLineTools SDK而不是XCode.app SDK。
我在编译PointCloudLibrary(PCL)时解决了此问题
ls -l
此外,重新安装XCode.app,CommandLineTools可能会有所帮助。
答案 6 :(得分:2)
重新安装Xcode,命令工具和自制软件, 和
sudo rm -rf /usr/local/include
为我修复了此问题。
答案 7 :(得分:1)
@solodon的分析很现场。根据头文件的搜索顺序,cmath
文件可能包含错误的math.h
版本。至少,这是我遇到相同错误时发生的事情。
扫描编译器输出中的#include <...> search starts here:
。您也可以使用(source)从命令行强制输出:
gcc -Wp,-v -E -
它看起来应该像这样:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
请注意,带有Toolchains
的路径位于带有Platforms
的路径之前。如果您的情况是相反的,则需要找出配置中的原因。对我来说,这是我的登录脚本中的CPLUS_INCLUDE_PATH
的显式设置。
违规代码:
XCBASE=`xcrun --show-sdk-path`
export CPLUS_INCLUDE_PATH=$XCBASE/usr/include
这是我尝试解决Xcode 11的一部分,不再提供SDK头文件的安装包。删除此代码后,我能够在我的C ++代码中成功包含cmath
。
如果您是来这里寻求解决方案的,则可能需要其他解决方案,但希望这有助于阐明似乎是此问题的根本原因的是头文件搜索路径顺序。
答案 8 :(得分:1)
@mkl的solution帮助解决类似的问题。谢谢。
在PCL的基础上编译项目也遇到了同样的问题。解决方案是设置CommandLineTools SDK CMAKE_OSX_SYSROOT。
我在CMakeLists.txt中尝试了@mkl的解决方案,它不起作用。这样我只能通过cmake .. -DCMAKE_OSX_SYSROOT="/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk"
要提及的另一件事:我的MacOS中有两个版本的命令行SDK:
~ » /Library/Developer/CommandLineTools/SDKs/MacOSX
/Library/Developer/CommandLineTools/SDKs/MacOSX
MacOSX.sdk/ MacOSX10.14.sdk@
xcrun --show-sdk-path
给出了默认值,但实际上只有MacOSX10.14.sdk支持我。
讨论PCL回购中的类似问题: https://github.com/PointCloudLibrary/pcl/issues/2601#issuecomment-621889211
我对c ++中的cmake和SDK不太了解。我在来自不同SDK的cmake构建日志中注意到的差异如下:
/Library/Developer/CommandLineTools/SDKs/MacOSX
:
-- Found OpenGL: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenGL.framework
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk
-- Found OpenGL: /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenGL.framework
默认情况下:
-- Found OpenGL: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenGL.framework
问题似乎发生在Opengl的SDK选择上。
如果有人可以提出建议,便表示赞赏。
答案 9 :(得分:0)
我发现我的项目中有文件math.h
。重命名后,问题消失了。接缝cmath
包含我的文件而不是系统文件。
答案 10 :(得分:0)
摘要:在我的案例中,构建脚本使用的是ios-cmake
工具链的旧版本(2.1.2),并将其更新为3.1.2,解决了cmath / math包含问题。
针对我的情况(clang,c ++,iOs目标)适应@Ryan H. gcc -Wp,-v -E -
提出的漂亮命令
clang -x c++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.4.sdk -Wp, -v -E -
在两个Catalina上(包括唯一安装了XCode 11.14.1的工具的处女)产生收益:
clang -cc1 version 11.0.3 (clang-1103.0.32.59) default target x86_64-apple-darwin19.4.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.4.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.4.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.4.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.3/include
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.4.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.4.sdk/System/Library/Frameworks (framework directory)
End of search list.
因此正确的包含路径是第一个不可忽略的包含路径,所有内容都可以正常运行,但事实并非如此。看来此问题来自ios-cmake工具链附加到编译调用的附加include命令:
CompileC /Users/<...>/build.Release.ios/<...>.o <...>.cpp normal arm64 c++ com.apple.compilers.llvm.clang.1_0.compiler
-Isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.4.sdk <...>
-I/Users/<...>/Build_iOS/build.Release.ios/build.arm/Binaries/Release/include
-Isystem /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.4.sdk/usr/include
-I/Users/<...>/Build_iOS/build.Release.ios/build.arm/src/<...>.build/Release-iphoneos/<...>/DerivedSources/arm64
...
罪魁祸首是-Isystem ...
行,这将导致cmath文件中的#include <math>
行最终加载错误的文件。
经过反复摆弄尝试修复cmake脚本后,我注意到ios-cmake的较旧版本,对其进行更新具有“唯一”的作用,即删除了不需要的-Isystem
行-其他所有内容几乎相同(除了一些编译器选项)
答案 11 :(得分:0)
我终于弄清楚了为什么这只会影响到某些人。当Catalina出现时,他们停止提供带有/ usr标头的命令行工具包。常见的解决方法是使用CPATH指向bashrc中的系统头,如下所示:
export CPATH=`xcrun --show-sdk-path`/usr/include
但是,这似乎弄乱了cmath和math.h的C ++包含路径排序(在其他答案中可以找到)。好消息是,当前的clang和gcc自制版本似乎不再需要设置CPATH来查找系统头文件。因此,您只需删除CPATH覆盖并完成它即可。
答案 12 :(得分:0)
删除 MacOSX10.15.sdk
有效。
就我而言,它发生在我 cmake llvm 项目并在 Xcode 中构建 cmake 项目时。编译LibEdit时检测到此错误。
我在我的 MBP 上成功编译了这个项目,但在我的 iMac 上失败了。两者都是一样的macOS 11.3.1,Xcode 12.5,Command Line Tools 12.5,其他配置也一样。
于是我对比了 cmake 日志,发现了不同的地方: 在 MBP 上,LibEdit 的日志是:
-- Found LibEdit: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include (found version ".")
在 iMac 上,LibEdit 的日志是:
-- Found LibEdit: /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include (found version ".")
这就是导致构建错误的原因。
CommandLineTools 目录文件完全相同:
MacOSX11.1.sdk,
MacOSX11.3.sdk,
MacOSX10.15.sdk,
MacOSX.sdk link to MacOSX11.3.sdk
MacOSX11.sdk link to MacOSX11.3.sdk
和Xcode中的两个命令行工具-首选项-位置都设置为Xcode12.5(12E262)
然后我在 iMac 上重新安装了 Xcode 和命令行工具。但是没用。
cmake 命令指定了 -DCMAKE_OSX_SYSROOT="/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk"
。还是没用。
我不知道还能在哪里设置。最后,我删除了 MacOSX10.15.sdk
,它起作用了。
答案 13 :(得分:-1)
编译器试图找到 math.h
,通常它会先在 /usr/local/include
下找到它,然后找到一个错误的。
修复它的一个简单方法是使用:mv /usr/local/include/math.h /usr/local/include/math_old.h
重命名它。然后编译器会尝试以下包含目录。