Where are the C headers in MacOS Mojave?
xcode-select --install
did work for me in Mojave. Maybe you can try installing XCode from Mac App Store, and then install developer tools?
Regarding header locations, I have Apples headers in /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
And if you install gcc via brew, it will add headers in /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
(Those are not Apple's headers, but GCC / GLIBC).
Using dtruss I can see that Apple clang uses the one in 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 now supports multiple SDKs and multiple installations of Xcode. The SDKs are inside Xcode.app, and Xcode.app is installed by default in Applications but may be elsewhere.
xcrun --show-sdk-path
will show a default SDK path, but there may be others. For example, one possible path is /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
. From there, usr/include
holds common public headers such as the standard C headers, and various Apple headers are in frameworks under System
.
In /Applications/Xcode.app/Contents/Developer/Platforms
, you will likely find folders for other platforms, such as iPhoneOS.platform
and AppleTVOS.platform
. Within those, Developer/SDKs
leads to SDKs for those platforms.
Per the following article: https://silvae86.github.io/sysadmin/mac/osx/mojave/beta/libxml2/2018/07/05/fixing-missing-headers-for-homebrew-in-mac-osx-mojave/
This will install the headers:
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg