且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

升级到Mojave后,无法使用`#include`编译C ++'hello world'

更新时间:2022-12-01 08:46:57

我遇到了同样的问题.

我在/Applications/.../MacOSX10.14.sdk/usr/include中安装了标题.我没有将g ++调用别名为始终使用-isysroot,而是将/Applications/.../MacOSX10.14.sdk/usr/include添加到了

I had the headers installed in /Applications/.../MacOSX10.14.sdk/usr/include. Instead of aliasing my g++ calls to always use -isysroot, I added /Applications/.../MacOSX10.14.sdk/usr/include to my CPLUS_INCLUDE_PATH.

我使用并添加到.bash_profile中的确切代码行是

The exact line of code I used and added to my .bash_profile was

export CPLUS_INCLUDE_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include

我觉得这是一个更优雅的解决方案,因为据我了解,使用 isysrootsysroot 会告诉g ++不要在默认位置搜索,这时您可能需要同时包含Mac SDK目录和通常的/usr/include/usr/local/include等.

I feel that this is a more elegant solution, since from what I understand using isysroot or sysroot will tell g++ to not search in the default places, when you may need includes from both the mac SDK directory and the usual /usr/include, /usr/local/include, and so on.