3
votes

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.

3
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... stackoverflow.com/a/32338889/2836621 - Mark Setchell
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
Did my answer, or any others, sort out your problem? If so, please consider accepting it as your answer - by clicking the hollow tick/checkmark beside the vote count. If not, please say what didn't work so that I, or someone else, can assist you further. Thanks. meta.stackexchange.com/questions/5234/… - Mark Setchell

3 Answers

2
votes

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

0
votes

try running following:

xcode-select --install

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

0
votes

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.