I have used the gcc command on the terminal to compile C programs but all of a sudden, after an update to my Mac's OS (to macOS 10.14 Mojave, and XCode 10.0), I started receiving the message:
test.c:8:10: fatal error: stdio.h: No such file or directory #include <stdio.h> ^~~~~~~~~ compilation terminated.
I already have gcc installed as I can find it in
/usr/local/bin and there really is a gcc in there. I tried running the same file on my other iMac and it worked without any issue.
I tried running
xcode-select --install and it already was installed, hence it didn't fix the issue I'm having now. I'm guessing that the path is messed up as it doesn't seem like it can find
gcc after I started copying and pasting some commands from other resources to solve this issue.
Would like some help on this.
Extracting a semi-coherent answer from rather extensive comments…
xcode-select --install has been the correct solution, but it does not seem to help this time. Have you tried running the main XCode GUI interface? It may install some extra software for you and clean up. I did that after installing XCode 10.0, but a week or more ago, long before upgrading to Mojave.
I observe that if your GCC is installed in
/usr/local/bin, you probably aren't using the GCC from XCode; that's normally installed in
I too have updated to macOS 10.14 Mojave and XCode 10.0. However, both the system
/usr/bin/gcc and system
/usr/bin/clang are working for me (
Apple LLVM version 10.0.0 (clang-1000.11.45.2) Target: x86_64-apple-darwin18.0.0 for both.) I have a problem with my home-built GCC 8.2.0 not finding headers in
/usr/include, which is parallel to your problem with
/usr/local/bin/gcc not finding headers either.
I've done a bit of comparison, and my Mojave machine has no
/usr/include at all, yet
/usr/bin/clang is able to compile OK. A header (
_stdio.h, with leading underscore) was in my old
/usr/include; it is missing now (hence my problem with GCC 8.2.0). I ran
xcode-select --install and it said "
xcode-select: note: install requested for command line developer tools" and then ran a GUI installer which showed me a licence which I agreed to, and it downloaded and installed the command line tools — or so it claimed.
I then ran XCode GUI (command-space, xcode, return) and it said it needed to install some more software, but still no
/usr/include. But I can compile with
/usr/bin/gcc — and the
-v option suggests they're using
I've found a way. If we are using XCode 10, you will notice that if you navigate to the
/usrin the Finder, you will not see a folder called 'include' any more, which is why the terminal complains of the absence of the header files which is contained inside the 'include' folder. In the XCode 10.0 Release Notes, it says there is a package:
and you should install that package to have the
/usr/includefolder installed. Then you should be good to go.
When all else fails, read the manual or, in this case, the release notes. I'm not dreadfully surprised to find Apple wanting to turn their backs on their Unix heritage, but I am disappointed. If they're careful, they could drive me away. Thank you for the information.
Having installed the package using the following command at the command line, I have
/usr/include again, and my GCC 8.2.0 works once more.