Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

xcode - Where are the C headers in MacOS Mojave?

It seems that Apple keeps on moving their tools around and the old solution of installing the command line tools are with using xcode-select --install doesn't work.

In Mojave, xcode-select doesn't install anything anymore (the GUI always fails to find the package) and the command line tools don't install itself in /usr/ or /usr/local.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

int main(void)
{
  printf("Hello, world\n");
  return 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", 0x1000000, 0x1A)             = -1 Err#2
3781/0x51d8:  open("/Library/Developer/CommandLineTools/usr/lib/clang/10.0.0/include/stdio.h", 0x1000000, 0x48)               = -1 Err#2
3781/0x51d8:  open("/Library/Developer/CommandLineTools/usr/include/stdio.h", 0x1000000, 0x37)                = -1 Err#2
3781/0x51d8:  open("/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h", 0x1000000, 0x47)                = 3 0

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...