fatal error: stdio.h: No such file or directory
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.
White Thigh
Updated on June 04, 2022Comments
-
White Thigh almost 2 years
I have a problem with
#include <stdio.h>
on mac Mojave 10.14.1I 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.
-
fdk1342 over 5 yearsSeems kind of strange that
gcc
was built only for c++ and fortran but you are trying to use it as ac
compiler. If you renameinverse.c
toinverse.cpp
does it work? -
Havenard over 5 years
Configured with: ../gcc-7.1.0/configure --enable-languages=c++,fortran
Yeah this looks odd, mine hasc
in this list, and without it I can't tell ifstdio.h
would be supported. Judging from the error message I'd say it is not. -
Shawn over 5 yearsDid you install xcode?
-
Eric Postpischil over 5 years@JonathanLeffler: Why do you think this us a duplicate? There are many ways software installations can be messed up. The issue there appeared to have been a broken Xcode/Apple tools installation. This question seems to involve some GCC version, which is different (Apple uses Clang now).
-
Jonathan Leffler over 5 years@EricPostpischil: Because the symptoms are the same — upgraded to Mojave and … No
stdio.h
was how I encountered the problem. -
Eric Postpischil over 5 years@JonathanLeffler: The question does not indicate there was an upgrade to Mojave from a previous macOS version, just that 10.14.1 is the version the issue is occurring on. And a comment has identified a likely cause: The GCC installation was configured for C++ and FORTRAN and hence does not support C.
-
Jonathan Leffler over 5 yearsSee Can't compile C program on a Mac after upgrade to Mojave for a probable solution to your problem. Not everyone agrees that your trouble will be resolved by the steps there, though I strongly suspect that what you're seeing is what I saw, and what the OP of that question saw — the system headers have been removed from
/usr/include
by Apple during an upgrade to Mojave. -
White Thigh over 5 years@Jonathan Leffler: Hi, according to your tip, I jumped to the "Can't compile C program on a Mac after upgrade to Mojave ". Then I tried to install the package (macOS_SDK_headers_for_macOS_10.14.pkg)
-
White Thigh over 5 years@Jonathan Leffler: However, terminal gives me this error:Error: macOS_SDK_headers_for_macOS_10.14.pkg: undefined method `xar!' for Formulary::FormulaNamespace03a5542d706800cf492f2f8aead0a0ff:Module
-
White Thigh over 5 years@Jonathan Leffler: Could you give me more advice and I was checking the release notes from Apple but not big help.
-