2

Before updating to Mojave I was compiling C programs just fine. I used an older version of gcc, 7.3, that I installed using the instructions found here.

Then I updated to Mojave and tried compiling the simple program that follows with gcc main.c:

#include <stdio.h>
int main(){
    printf("Hello World\n");
    return 0;}

This results in the following error:

/usr/local/lib/gcc/x86_64-apple-darwin17.5.0/7.3.0/include-fixed/stdio.h:78:10: fatal error: _stdio.h: No such file or directory
 #include <_stdio.h>
      ^~~~~~~~~~
compilation terminated.

If I remove the include it will compile with implicit declaration warnings for printf, but will still compile and run properly, printing Hello World. Does anyone know the issue and how I can fix it?

user906357
  • 4,575
  • 7
  • 28
  • 38
  • 2
    I ran the program you pasted above and it ran fine for me. However, when I changed `stdio.h` to `_stdio.h`, I got the same error. I would just double check and make sure you didn't have a typo over there. If that's not the issue then it has to do with with some bug in the compiler. Try installing a different one? – Bilal Saleem Oct 24 '18 at 17:02
  • I think you have to start the Xcode GUI at least once after upgrading to Mojave and do updates then it works. – Mark Setchell Oct 24 '18 at 17:06
  • 1
    @BilalSaleem: This issue is not caused by a typo, as is evident from the error message that shows the attempt to include `_stdio.h` comes from `stdio.h` in some installation path, not a source or header file in the usual user path. This is evidence of a broken compiler installation. – Eric Postpischil Oct 24 '18 at 18:56
  • 2
    Not sure this is a duplicate, but see these potential originals: [1](https://stackoverflow.com/questions/52509602/cant-compile-c-program-on-a-mac-after-upgrade-to-mojave), [2](https://stackoverflow.com/questions/19580758/gcc-fatal-error-stdio-h-no-such-file-or-directory). – Eric Postpischil Oct 24 '18 at 19:00
  • Possible duplicate of [Can't compile C program on a Mac after upgrade to Mojave](https://stackoverflow.com/questions/52509602/cant-compile-c-program-on-a-mac-after-upgrade-to-mojave) – paulsm4 Oct 24 '18 at 19:45

1 Answers1

3

I figured out how to fix it. I went to

/Library/Developer/CommandLineTools/Packages/

then opened and installed macOS_SDK_headers_for_macOS_10.14.pkg.

user906357
  • 4,575
  • 7
  • 28
  • 38
  • At first glance, I thought this might be a typo in your source code. Then I noticed Eric Postpischil's comment: the compiler is correctly finding `"stdio.h" ... but stdio.h is looking for "_stdio.h" ... which was missing. Glad you got it figured out, and thank you for posting the solution! – paulsm4 Oct 24 '18 at 19:42
  • Thank you so much for finding this! Installing gcc-8 with homebrew has the same issue and this solution is the only thing that worked. – Vesal Nov 05 '18 at 21:11
  • This file does not exist on macOS Mojave. – Pedro Paulo Amorim Mar 12 '20 at 10:53