5

So was trying to compile a c file (via a makefile) and got the "fatal error: stdio.h: No such file or directory" . This compiles on just fine via cygwin and a remote linux box just not my mac (so the files are okay).

I have installed the mac command line tools as mentioned in this question. When I do gcc --version I am getting 5.3 but if i do brew info gcc i get 8.2. When I do a find through terminal I can the file, so not sure what is up.

ChrisS
  • 61
  • 1
  • 5
  • You need to think about whether your program is C or C++ as you seem to confuse the two at every step. Use `g++` for C++ programs and tag C++. Use `gcc` for C programs and tag C. Have a look here... https://stackoverflow.com/a/32338889/2836621 – Mark Setchell Oct 13 '18 at 22:08
  • Mark yes you are correct, I was using the terms incorrectly, my bad. However, this still doesn't solve the underlying issue. The Makefile I built works just fine (and uses gcc as its a c not c++ program) via Cygwin on my PC and my remote Linux server. However, I get the error I mentioned when running the makefile on my mac, so its something with my gcc install/version/? and my mac. – ChrisS Oct 25 '18 at 00:00

4 Answers4

2

If you run:

which gcc

you will get /usr/bin/gcc which is the compiler supplied by Apple as part of macOS.

Presumably, since you mention homebrew, you mean to use the compiler installed by homebrew. So, you need to look in /usr/local/bin and see what homebrew has installed:

ls -l /usr/local/bin/gcc*
lrwxr-xr-x  1 mark  admin  29 17 Sep 10:53 /usr/local/bin/gcc-8 -> ../Cellar/gcc/8.2.0/bin/gcc-8

So, the answer to your question is:

  • firstly, you need to have /usr/local/bin at the start of your PATH, and
  • secondly, you need to use the following command to compile:

gcc-8 main.c -o main

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
0

try running following:

xcode-select --install

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

fahad
  • 66
  • 4
  • As I mentioned in the original post, I have already done that and it did not resolve the issue. The files are fine, the code compiles and runs on my PC and remote linux box. The only issue is trying to compile on my mac. – ChrisS Oct 25 '18 at 00:02
0

With Mojave and XCODE 10, the problem is that the "include" folder is no longer automatically included when you install the command line tools. Instead, you need to do an "open" on /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg That solved the identical problem for me, anyway.

0

I ran into this issue and this is how I resolved it.

softwareupdate --all --install --force
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install

Basically developer framework is likely to be broken. But simply running xcode-select --install may not work because it will say the xcode developer tools are already installed (despite its broken status). So I had to completely wipe out any existing installation and install the developer framework again.

FYI if everything is installed correctly, the header files should be found at:

 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
Jongwook Choi
  • 8,171
  • 3
  • 25
  • 22