且构网

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

升级到 Catalina 10.15 后无法在 Mac 上编译 C 程序

更新时间:2023-01-14 21:48:37

对于我来说,将以下路径添加到 CPATH 解决了这个问题:

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

There's a previous question Can't compile C program on a Mac after upgrade to Mojave, and the answers to that have covered most of the variations on what goes wrong.

Now — as of Monday 2019-10-07 — you can upgrade to macOS Catalina 10.15. Once again, during the upgrade, the /usr/include directory has been blown away by the update, even though XCode 11.0 was installed before upgrading (from Mojave 10.14.6) to Catalina. Consequently, compilers built to expect that there is a /usr/include directory do not work any longer.

The main recommended step for the Mojave issues — using the command:

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

does not work out of the gate because the directory /Library/Developer/CommandLineTools/Packages/ does not exist (so there's not yet a .pkg file to open).

Is there a good (official) way to create and populate the directory /usr/include?

For me adding the following path to CPATH solved the issue:

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