0

mac book pro, ios newest version. gcc is installed, and xcode-select --install is done.

when I ran gcc path/to/hello.c, I got the following error

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

It was first shown when I tried to upgrade regex (module of python) with pip3. hello.c is just a test for gcc.

There is a similar topic in the forum, but I don't understand yet. How do I fix the problem.

William Song
  • 577
  • 6
  • 17
  • What does `which gcc` tell you? What does `gcc --version` tell you? – John Zwinck Nov 11 '17 at 03:02
  • `stdio.h` is part of the basic set of headers that would be shipped with your compiler if it were installed correctly. – Charles Duffy Nov 11 '17 at 03:02
  • @JohnZwinck, ...I'm assuming it's not really gcc but Apple's gcc-compatibility wrapper for LLVM. Well, replace "assuming" with *hoping*; installing actual gcc on current MacOS would be putting the OP in a not-very-well-supported scenario. – Charles Duffy Nov 11 '17 at 03:02
  • @JohnZwinck gcc --version gcc (Homebrew GCC 7.1.0) 7.1.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. – William Song Nov 11 '17 at 06:26
  • @Charles Duffy it is in usr/include. – William Song Nov 11 '17 at 06:28
  • @JohnZwinck which gcc /usr/local/bin/gcc – William Song Nov 11 '17 at 06:33
  • Is there /usr/local/include/stdio.h? – John Zwinck Nov 11 '17 at 06:45
  • 1
    Possible duplicate of [GCC fatal error: stdio.h: No such file or directory](https://stackoverflow.com/questions/19580758/gcc-fatal-error-stdio-h-no-such-file-or-directory) – Florian Weimer Nov 11 '17 at 07:21
  • @JohnZwinck no! there are only a few files in the path fewer then usr/include. – William Song Nov 11 '17 at 10:55
  • @WilliamSong, you shouldn't be installing gcc with homebrew. Use the copy that comes with XCode. (Well, it's not actually a copy of gcc at all -- it's a wrapper around LLVM that makes it support gcc command-line usage -- but still, it's what you should be using). – Charles Duffy Nov 11 '17 at 17:16
  • @CharlesDuffy I am confused. Do I have to use gcc in xcode? How to use it? How do I make the command `gcc hello.c` work. In xcode, I can run c files. – William Song Nov 12 '17 at 01:28
  • `gcc` is provided by xcode if you have it installed with the optional command-line tools. You can use it from the Terminal -- without even having Homebrew or MacPorts installed at all -- if your installation is complete/correct. – Charles Duffy Nov 12 '17 at 01:43
  • If you haven't done so already, uninstall your Homebrew install of gcc, and run `sudo xcode-select --install`. – Charles Duffy Nov 12 '17 at 01:45
  • 1
    @CharlesDuffy I just run `brew uninstall gcc` twice, there are two versions of gcc. Thank you very much. It works now. – William Song Nov 12 '17 at 02:04

1 Answers1

1

On Macos, the header files come with the system compiler (the Xcode environment). The compilers distributed by Homebrew do not include them, so you still need to install Xcode and use tools such as xcode-select and xcrun.

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92