C语言 GCC 致命错误:stdio.h:没有这样的文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19580758/
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
GCC fatal error: stdio.h: No such file or directory
提问by Jules
I'm trying to compile a program in C on OS X 10.9 with GCC 4.9 (experimental). For some reason, I'm getting the following error at compile time:
我正在尝试使用 GCC 4.9(实验性)在 OS X 10.9 上用 C 编译程序。出于某种原因,我在编译时收到以下错误:
gcc: fatal error: stdio.h: No such file or directory
I then tried a simple Hello World program:
然后我尝试了一个简单的 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?
同样,在运行时gcc -o ~/hello ~/hello.c,我遇到了同样的错误。我使用的实验版gcc,但它似乎难以置信会有其生成的错误导入时释放stdio。什么可能导致此问题,如何解决?
回答by amos
Mac OS X
Mac OS X
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:
我也有这个问题(通过 Macports 编译器遇到)。以前版本的 Xcode 可以让您通过 xcode/Preferences 安装命令行工具,但 xcode5 没有在 GUI 中提供命令行工具选项,所以我认为它现在已自动包含在内。尝试运行此命令:
xcode-select --install
Ubuntu
Ubuntu
(as per this answer)
(根据这个答案)
sudo apt-get install libc6-dev
Alpine Linux
阿尔卑斯Linux
(as per this comment)
(根据此评论)
apk add libc-dev
回答by Samshel
Mac OS Mojave
Mac OS 莫哈韦沙漠
The accepted answer no longer works. When running the command xcode-select --installit tells you to use "Software Update" to install updates.
接受的答案不再有效。运行该命令时,xcode-select --install它会告诉您使用“软件更新”来安装更新。
In this linkis the updated method:
在此链接中是更新的方法:
Open a Terminal and then:
打开终端,然后:
cd /Library/Developer/CommandLineTools/Packages/
open macOS_SDK_headers_for_macOS_10.14.pkg
This will open an installation Wizard.
这将打开一个安装向导。
Update 12/2019
12/2019 更新
After updating to Mojave 10.15.1 it seems that using xcode-select --installworks as intended.
更新到 Mojave 10.15.1 后,似乎xcode-select --install可以按预期使用。
回答by equivalent8
ubuntu users:
ubuntu 用户:
sudo apt-get install libc6-dev
sudo apt-get install libc6-dev
specially ruby developers that have problem installing gem install json -v '1.8.2'on their VMs
特别是gem install json -v '1.8.2'在他们的虚拟机上安装有问题的 ruby 开发人员
回答by nevieandphil
I had the same problem. I installed "XCode: development tools" from the app store and it fixed the problem for me.
我有同样的问题。我从应用商店安装了“XCode:开发工具”,它为我解决了这个问题。
I think this link will help: https://itunes.apple.com/us/app/xcode/id497799835?mt=12&ls=1
我认为这个链接会有所帮助:https: //itunes.apple.com/us/app/xcode/id497799835?mt=12&ls=1
Credit to Yann Ramin for his advice. I think there is a better solution with links, but this was easy and fast.
感谢 Yann Ramin 的建议。我认为有一个更好的链接解决方案,但这既简单又快速。
Good luck!
祝你好运!
回答by Soid
I know my case is rare, but I'll still add it here for someone who troubleshoots it later. 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. Making it a separate target solved the problem.
我知道我的情况很少见,但我仍然会在此处添加它,以便稍后对其进行故障排除。我的 Makefile 中有一个 Linux 内核模块目标,我尝试将我的用户空间程序与没有 stdio 的内核模块一起编译。使它成为一个单独的目标解决了这个问题。

