Apple 似乎一直在改变他们的工具,而安装命令行工具的旧解决方案是使用
xcode-select --install
不起作用。
在 Mojave 中,
xcode-select
不再安装任何东西(GUI 总是找不到软件包)并且命令行工具不会在 /usr/
或 /usr/local
中自行安装。
xcode-select --install
在莫哈韦为我工作。也许你可以尝试从Mac App Store安装XCode,然后安装开发者工具?
关于标题位置,我在
/Library/Developer/CommandLineTools/
中有苹果标题:
$ sudo find /Library -name stdio.h
/Library/Developer/CommandLineTools/usr/include/c++/v1/stdio.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/stdio.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/stdio.h
如果你通过brew安装gcc,它会在
/usr/local/
中添加标头:
$ sudo find /usr -name stdio.h
/usr/local/Cellar/gcc/8.2.0/include/c++/8.2.0/tr1/stdio.h
/usr/local/Cellar/gcc/8.2.0/lib/gcc/8/gcc/x86_64-apple-darwin17.7.0/8.2.0/include/ssp/stdio.h
/usr/local/Cellar/gcc/8.2.0/lib/gcc/8/gcc/x86_64-apple-darwin17.7.0/8.2.0/include-fixed/stdio.h
/usr/local/Cellar/gcc/8.1.0/include/c++/8.1.0/tr1/stdio.h
/usr/local/Cellar/gcc/8.1.0/lib/gcc/8/gcc/x86_64-apple-darwin17.5.0/8.1.0/include/ssp/stdio.h
/usr/local/Cellar/gcc/8.1.0/lib/gcc/8/gcc/x86_64-apple-darwin17.5.0/8.1.0/include-fixed/stdio.h
/usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/tr1/stdio.h
/usr/local/Cellar/gcc/7.3.0_1/lib/gcc/7/gcc/x86_64-apple-darwin17.3.0/7.3.0/include/ssp/stdio.h
/usr/local/Cellar/gcc@7/7.3.0/include/c++/7.3.0/tr1/stdio.h
/usr/local/Cellar/gcc@7/7.3.0/lib/gcc/7/gcc/x86_64-apple-darwin17.5.0/7.3.0/include/ssp/stdio.h
/usr/local/Cellar/gcc@7/7.3.0/lib/gcc/7/gcc/x86_64-apple-darwin17.5.0/7.3.0/include-fixed/stdio.h
/usr/local/include/c++/8.2.0/tr1/stdio.h
/usr/local/lib/gcc/8/gcc/x86_64-apple-darwin17.7.0/8.2.0/include/ssp/stdio.h
/usr/local/lib/gcc/8/gcc/x86_64-apple-darwin17.7.0/8.2.0/include-fixed/stdio.h
(这些不是 Apple 的标头,而是 GCC / GLIBC)。
使用 dtruss 我可以看到 Apple clang 使用
CommandLineTools/SDKs
中的那个:
$ sudo dtruss -f sudo -u $USER clang test.c -o test 2>&1
3781/0x51d8: pread(0x3, "#include <stdio.h>\n\nint main(void)\n{\n printf(\"Hello, world\\n\");\n return 0;\n}\n\0", 0x4F, 0x0) = 79 0
3781/0x51d8: __pthread_sigmask(0x3, 0x7FFEE3A7E768, 0x7FFEE3A7E76C) = 0 0
3781/0x51d8: close(0x3) = 0 0
3781/0x51d8: __pthread_sigmask(0x3, 0x7FFEE3A7E76C, 0x0) = 0 0
3781/0x51d8: open("/usr/local/include/stdio.h\0", 0x1000000, 0x1A) = -1 Err#2
3781/0x51d8: open("/Library/Developer/CommandLineTools/usr/lib/clang/10.0.0/include/stdio.h\0", 0x1000000, 0x48) = -1 Err#2
3781/0x51d8: open("/Library/Developer/CommandLineTools/usr/include/stdio.h\0", 0x1000000, 0x37) = -1 Err#2
3781/0x51d8: open("/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h\0", 0x1000000, 0x47) = 3 0
Xcode 现在支持多个 SDK 以及在不同位置多次安装 Xcode。 SDK 位于 Xcode.app 内,Xcode.app 默认安装在应用程序中,但也可能位于其他位置。
xcrun --show-sdk-path
将显示默认的 SDK 路径,但可能还有其他路径。例如,一种可能的路径是/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
。从那里开始, usr/include
保存常见的公共标头,例如标准 C 标头,并且各种 Apple 标头位于 System
下的框架中。
在
/Applications/Xcode.app/Contents/Developer/Platforms
中,您可能会找到其他平台的文件夹,例如 iPhoneOS.platform
和 AppleTVOS.platform
。其中,Developer/SDKs
带来了适用于这些平台的 SDK。
这将安装标头:
打开/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg