Justin
Justin

Reputation: 577

stdio.h file not found when compiling c program

#include <stdio.h>

int main(void)
{
    printf ("Programming is fun");

    return 0;
}

When I use the cc command in terminal to compile the above program it returns

fatal error: 'stdio.h' file not found`

I compiled this exact code on ubuntu where it created an a.out-file, which sadly did not run either. While I'm not sure why either happens at least no error was produced on ubuntu.

Upvotes: 0

Views: 11361

Answers (4)

igonejack
igonejack

Reputation: 2532

For recent macOS, people would miss C headers after system update.

cd /Library/Developer/CommandLineTools/Packages
open macOS_SDK_headers_for_macOS_xx.pgk

I guess this is another Apple's bug.

Upvotes: 2

ntremble
ntremble

Reputation: 71

Before you go reinstalling your compiler you might want to check your include paths. As you don't specify your platform I can only provide general information but this is similar on many platforms.

Using cc you need to set them in the environment. Try typing 'env' to see your current settings. There needs to be a line that sets a variable 'include' with the full path to the location of your studio.h.

You can also set the include path in the make file or, if using an IDE, in the project settings.

Upvotes: 1

Macmade
Macmade

Reputation: 53970

You don't specify the platform you're on...

If stdio.h is not found, it usually mean you don't have the necessary header files on your system (usually in /usr/include/).

Your compiler might be working fine, but it looks like the C-Library headers are not installed.

Depending on your platform, you'll have to install them.
It's a bit weird that you have a working compiler without C library headers.

You may want to reinstall your compiler, or search for a package which contains the headers for the C library.

If you're on OS X, (re)install Xcode as well as the command line tools.

If you're on Linux, use your package manager to install the development package for C (e.g. libc6-dev on Debian).

Upvotes: 1

user3344003
user3344003

Reputation: 21627

There is something wrong with how your compiler is configured.

Upvotes: -2

Related Questions