Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

gcc

stdio

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: fatal error: stdio.h: No such file or directory 

I then tried a simple Hello World program:

#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?

like image 313
Jules Avatar asked Oct 25 '13 03:10

Jules


People also ask

How do I fix GCC fatal error?

How do I fix GCC fatal error no input files? Make sure that you are running gcc s1. c while you are in program directory or you can try gcc program/s1. c if you are not in program directory.

What is #include stdio h in C program?

If we use #include<stdio. h> in your c program, it will include stdio. h file into our source program which has the information for all input, output related functions.

Where is Stdio H on Windows?

The File Stdio. h is included in the path C:\Program Files (x86)\Windows Kits\10\Include\10.0. 17134.0\ucrt.

Where is Stdio H located in Ubuntu?

p.s. the standard location on *nix systems would be /usr/include/stdio. h, i.e., #include looks in /usr/include and other -I directories passed as arguments to the compiler. Save this answer. Show activity on this post.


2 Answers

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 

If you see an error message that developer tools are already installed (and still header files can't be found), wipe out any existing one to do a fresh installation:

sudo rm -rf /Library/Developer/CommandLineTools 

Ubuntu

(as per this answer)

sudo apt-get install libc6-dev 

Alpine Linux

(as per this comment)

apk add libc-dev 
like image 181
amos Avatar answered Oct 24 '22 13:10

amos


Mac OS Mojave

The accepted answer no longer works. When running the command xcode-select --install it tells you to use "Software Update" to install updates.

In this link is 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

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

like image 37
Samshel Avatar answered Oct 24 '22 15:10

Samshel