GCC 致命错误: stdio.h: 没有这样的文件或目录

我正在尝试用 OS X 10.9中的 C 语言和 GCC 4.9(实验)编译一个程序。由于某种原因,我在编译时遇到了以下错误:

gcc: fatal error: stdio.h: No such file or directory

然后我尝试了一个简单的 Hello World 程序:

#include <stdio.h>


int main(int argc, const char *argv[])
{
printf("Hello, world!");
return 0;
}

Again, upon running gcc -o ~/hello ~/hello.c, I got the same error. I'm using an experimental version of gcc, but it seems implausible that there would be a release which generated errors upon importing stdio. What could be causing this issue, and how can it be fixed?

282029 次浏览

我也有同样的问题。我从应用程序商店安装了“ XCode: development tools”,它帮我解决了这个问题。

我认为这个链接会有所帮助: Https://itunes.apple.com/us/app/xcode/id497799835?mt=12&ls=1

感谢 Yann Ramin 的建议。我认为有一个更好的解决方案与链接,但这是容易和快速。

祝你好运!

MacOS

I had this problem too (encountered through Macports compilers). Previous versions of Xcode would let you install command line tools through xcode/Preferences, but xcode5 doesn't give a command line tools option in the GUI, that so I assumed it was automatically included now. Try running this command:

xcode-select --install

如果您看到一个错误消息,开发人员工具已经安装(仍然无法找到头文件) ,删除任何现有的一个做一个新的安装:

sudo rm -rf /Library/Developer/CommandLineTools

Ubuntu

(根据此 answer)

sudo apt-get install libc6-dev

高山 Linux

(根据此 comment)

apk add libc-dev

ubuntu users:

sudo apt-get install libc6-dev

特别是在 VM 上安装 gem install json -v '1.8.2'有问题的 Ruby 开发人员

Mac OS 莫哈韦沙漠

已被接受的答案不再有效。当运行命令 xcode-select --install时,它告诉您使用“软件更新”来安装更新。

在这个 链接是更新的方法:

打开终端机,然后:

cd /Library/Developer/CommandLineTools/Packages/
open macOS_SDK_headers_for_macOS_10.14.pkg

这将打开安装向导。

Update 12/2019

After updating to Mojave 10.15.1 it seems that using xcode-select --install works as intended.

我知道我的情况是罕见的,但我仍然会添加到这里的人谁解决它以后。 I had a Linux Kernel module target in my Makefile and I tried to compile my user space program together with the kernel module that doesn't have stdio. 让它成为一个单独的目标解决了问题。