Broken gcc on macOS Mojave

Viewed 5137

It seems like my gcc is broken.

When I try to install package from PyPI I have this error:

    ./uwsgi.h:165:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
         ^~~~~~~~~
1 error generated.
In file included from core/protocol.c:1:
./uwsgi.h:165:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
         ^~~~~~~~~
1 error generated.

XCode command line tools are installed:

    ➜  xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

And gcc from brew installed:

➜  brew install gcc
Warning: gcc 8.2.0 is already installed and up-to-date
To reinstall 8.2.0, run `brew reinstall gcc`

When I try to recognize which gcc is used I have /usr/bin/gcc. I think it's XCode version.

But there is no gcc binary in brew:

➜  ls /usr/local/bin/gcc-*
/usr/local/bin/gcc-8        /usr/local/bin/gcc-ar-8     /usr/local/bin/gcc-nm-8     /usr/local/bin/gcc-ranlib-8

What can I do in this situation? How can I fix gcc?

3 Answers

The correct answer was in this thread: https://stackoverflow.com/a/52530212/1377912

The new Xcode doesn't provide headers by default. You should install it manually:

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

As I wrote this answer, Mojave is deprecated and now is the age of Big Sur! but this problem still exists!

I don't know that following command will work on Mojave or not, but is working on Big Sur! if you still have this problem, just simply examine that.

Just set CFLAGS(for C compilers) or CXXFLAGS (for C++ compilers ) something like this:

export CFLAGS="-isysroot $(xcrun --sdk macosx --show-sdk-path) -I/usr/include -L/usr/lib -I$(xcrun --sdk macosx --show-sdk-path)/usr/include"

or

export CXXFLAGS="-isysroot $(xcrun --sdk macosx --show-sdk-path) -I/usr/include -L/usr/lib -I$(xcrun --sdk macosx --show-sdk-path)/usr/include"

It probably removes your fatal error: 'stdio.h' file not found error. If this error been removed, it might that you face to new problems, don't count them as this problem and loose your success by manipulating this! In this situation just be care about your new problems and try to fix them, one by one!

I hope this answer be useful for you

Maybe it's a stupid answer but have you tried to create and compile a very simple c file? However in my mojave system i've tried the gcc -v command and i have this output:

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include- 
dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.10.44.2)
Target: x86_64-apple-darwin18.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Related