我正在使用OSX Yosemite,我从homebrew安装了gcc-4.8
。
以下程序在编译时失败(例如:gcc-4.8 main.c
):
#include <stdio.h>
int main(void)
{
printf("hello world");
return 0;
}
出现错误:
main.c:8:19: fatal error: stdio.h: No such file or directory
#include <stdio.h>
^
compilation terminated.
并且。
$`gcc-4.8 -print-prog-name=cc1` -v
产出
ignoring nonexistent directory "/usr/local/Cellar/gcc48/4.8.4/lib/gcc/4.8/gcc/x86_64-apple-darwin14.3.0/4.8.4/../../../../../../x86_64-apple-darwin14.3.0/include"
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/Cellar/gcc48/4.8.4/lib/gcc/4.8/gcc/x86_64-apple-darwin14.3.0/4.8.4/include
/usr/local/include
/usr/local/Cellar/gcc48/4.8.4/include
/usr/local/Cellar/gcc48/4.8.4/lib/gcc/4.8/gcc/x86_64-apple-darwin14.3.0/4.8.4/include-fixed
/System/Library/Frameworks
/Library/Frameworks
End of search list.
并且
$ find /usr/local/ -name "stdio.h" -print
产量
/usr/local//Cellar/gcc/5.2.0/include/c++/5.2.0/tr1/stdio.h
/usr/local//Cellar/gcc/5.2.0/lib/gcc/5/gcc/x86_64-apple-darwin14.4.0/5.2.0/include/ssp/stdio.h
/usr/local//Cellar/gcc48/4.8.4/include/c++/4.8.4/tr1/stdio.h
/usr/local//Cellar/gcc48/4.8.4/lib/gcc/4.8/gcc/x86_64-apple-darwin14.3.0/4.8.4/include/ssp/stdio.h
/usr/local//include/c++/4.8.4/tr1/stdio.h
/usr/local//lib/gcc/4.8/gcc/x86_64-apple-darwin14.3.0/4.8.4/include/ssp/stdio.h
现在我知道我可以传递-I /path/to/directory
让编译器找到正确的头文件,但是这是stdio.h
!我不想为了一些小程序而这样做。有什么方法可以解决这个问题吗?
/usr/include
)。XCode将其头文件隐藏在某个神秘的地方。当我运行clang -v
编译一个文件时,它列出了/usr/local/include
、/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/7.0.2/include
、/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
、/usr/include
,但我已经安装了命令行工具。 - Jonathan Lefflergcc
,而XCode安装了一个完全可用的、事实上更加功能强大的编译器(例如,您将拥有更好的泄漏检测软件)... - autistic/usr
中的C库头文件(以及提供汇编器和链接器,我想)。 - Jonathan Wakely