White Thigh
White Thigh

Reputation: 41

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

I have a problem with #include <stdio.h> on mac Mojave 10.14.1

I have a default gcc compiler together with other gcc compilers.

DorothyeMacBook:Desktop dorothy$ which gcc
/usr/local/bin/gcc

The version is

DorothyeMacBook:Desktop dorothy$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin15.6.0/7.1.0/lto-wrapper
Target: x86_64-apple-darwin15.6.0
Configured with: ../gcc-7.1.0/configure --enable-languages=c++,fortran
Thread model: posix
gcc version 7.1.0 (GCC) 

Now I am in the path : /Users/dorothy/Desktop

I have stdio.h in the lib

DorothyeMacBook:Desktop dorothy$ find /usr -name "stdio.h"
find: /usr/sbin/authserver: Permission denied
/usr/local/include/c++/7.1.0/tr1/stdio.h
/usr/local/include/c++/4.9.2/tr1/stdio.h
/usr/local/lib/gcc/x86_64-apple-darwin15.6.0/7.1.0/include/ssp/stdio.h
/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/include/ssp/stdio.h
/usr/local/Cellar/gcc/8.2.0/include/c++/8.2.0/tr1/stdio.h
/usr/local/Cellar/gcc/8.2.0/lib/gcc/8/gcc/x86_64-apple-darwin18.2.0/8.2.0/include/ssp/stdio.h
/usr/local/Cellar/gcc/8.2.0/lib/gcc/8/gcc/x86_64-apple-darwin18.2.0/8.2.0/include-fixed/stdio.h

However when I compile the file under the current path /Users/dorothy/Desktop Terminal will give me an error:

DorothyeMacBook:Desktop dorothy$ gcc  inverse.c -o inv
inverse.c:1:10: fatal error: stdio.h: No such file or directory
 #include <stdio.h>
          ^~~~~~~~~
compilation terminated.

Upvotes: 2

Views: 19250

Answers (2)

White Thigh
White Thigh

Reputation: 41

I still have a problem linking gcc with stdio.h on my mac. However, I have found an alternative way to compile the program with gcc. I typed brew install gcc in my terminal, that means a new gcc8.0.2 will be installed.(which is my case, I don't know what gcc you will get) Then I use gcc-8 instead of gcc to compile my program. In this way, the new gcc8.0.2 is invoked.

You can check the command name for gcc variants by going to /usr/local/bin All the names for gcc commands are listed there. As for me, those are

g++                 
g++-8               
gcc                 
gcc-8 

If you have further question, you can contact me and I will give more details.

Upvotes: 1

Kelly Hwong
Kelly Hwong

Reputation: 39

@Jonathan Leffler is right. Apple made another big cake for us. Since /usr/include has been moved (now it in /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include after you install commandline tools), old versions of gcc build cannot find the most bottom level include files. And this is a problem. (What are there in their head) So only you are developer you use /usr/include?

This is NOT Unix-like.

Here is what happened. For gcc-4.9(gcc-4.9 and gcc-9 below are all brew gcc.), the include search paths are:

enter ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
.
/usr/local/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
/usr/local/Cellar/[email protected]/4.9.4_1/lib/gcc/4.9/gcc/x86_64-apple-darwin17.3.0/4.9.4/include
/usr/local/Cellar/[email protected]/4.9.4_1/include
/usr/local/Cellar/[email protected]/4.9.4_1/lib/gcc/4.9/gcc/x86_64-apple-darwin17.3.0/4.9.4/include-fixed
/System/Library/Frameworks
/Library/Frameworks
End of search list. here

There is system level file stdio.h, this is why stdio.h cannot be found.

The problem in:

inverse.c:1:10: fatal error: stdio.h: No such file or directory
#include <stdio.h>
      ^~~~~~~~~
compilation terminated.

is:

Refer to /usr/local/Cellar/[email protected]/4.9.4_1/lib/gcc/4.9/gcc/x86_64-apple-darwin17.3.0/4.9.4/include/ssp/stdio.h

#ifndef _SSP_STDIO_H
#define _SSP_STDIO_H 1

#include <ssp.h>
#include_next <stdio.h>

#include_next means include next one name stdio.h, this one is just a guider.

Give a deprecated shot. cp all files in /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include to /usr/local/Cellar/[email protected]/4.9.4_1/lib/gcc/4.9/gcc/x86_64-apple-darwin17.3.0/4.9.4/include-fixed, gcc-4.9 will work again.

But for gcc-9 the path problem is fine. See:

#include "..." search starts here:
#include <...> search starts here:
.
/usr/local/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include # key path
/usr/local/Cellar/gcc/9.1.0/lib/gcc/9/gcc/x86_64-apple-darwin18/9.1.0/include
/usr/local/Cellar/gcc/9.1.0/lib/gcc/9/gcc/x86_64-apple-darwin18/9.1.0/include-fixed
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks
End of search list.

Actually this bug can be simply fixed by reinstall xcode commandline tools, after that gcc-4.9 will work again.

Upvotes: 0

Related Questions