C++ 通过`gcc -v`查看Mac OS X中C头文件的默认包含路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19852199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
View default include path of C headers in Mac OS X by `gcc -v`?
提问by Hanfei Sun
I tried to find the default include path of the C compiler in Mac OS X (Mavericks) by using gcc -v
:
我尝试使用gcc -v
以下命令在 Mac OS X (Mavericks) 中找到 C 编译器的默认包含路径:
$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
It seems to tell me the path is /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1
, but I'm afraid it is not the true path. I think the true path for including standard C library is /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include
because <sys/syscall.h>
locates in the later path, which is /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/sys/syscall.h
它似乎告诉我路径是/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1
,但恐怕它不是真正的路径。我认为包含标准C库的真正路径是/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include
因为<sys/syscall.h>
位于后面的路径中,即/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/sys/syscall.h
Does anyone have ideas about how to view all the default include path of C library in Mac OS X?
有没有人知道如何在 Mac OS X 中查看 C 库的所有默认包含路径?
回答by devnull
You need to ask the preprocessor, not gcc, for telling the default include path.
您需要询问preprocessor,而不是gcc,以告知默认包含路径。
You can say:
你可以说:
`gcc -print-prog-name=cc1` -v
In order to list default include path for both C and C++:
为了列出 C 和 C++ 的默认包含路径:
`gcc -print-prog-name=cc1plus` -v
(The paththat you've listed above is the one that was used to configureGCC while building.)
(您在上面列出的路径是用于在构建时配置GCC的路径。)
Another way to list the default include path would be:
列出默认包含路径的另一种方法是:
gcc -x c -v -E /dev/null
gcc -x c++ -v -E /dev/null # (for C/C++)