Space Cat, Prince Among Thieves

Fix Missing Headers Compiling on macOS Mojave

Update It would appear that the latest version of Xcode has removed the macOS_SDK_headers_for_macOS_10.14.pkg file. I am currently searching for alternative solutions.

While trying to compile PHP extensions after installing macOS Mojave, I was butting up against a ton of missing header file errors including php.h and zlib.

After several hours of beating my head against my desk and Googling/Stack Overflowing I found the solution.

Ends up you just need to force re-install the header files. Special thanks to @sfdye for the solution!

$ sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

If you get an error about that file not existing, you probably simply don't have the Xcode command line tools installed which can be remedied simply as follows:

$ xcode-select --install

Comment by: Matthew Koski on

Matthew Koski GravatarThank you so much for this! Google please make this the number one result when someone is having trouble with headers suddenly on Mojave. For me it was ctypes.h.

Comment by: Pooya Raki on

Pooya Raki GravatarThanks so much dude, It worked indeed. Gonna share this on my blog.

Comment by: Pablo on

Pablo GravatarThanks, solved my issues when compiling C++ as well!

Comment by: Ali on

Ali GravatarAfter beating my head to against my desk, walls, laptop, and every single thing around me for a whole week, finally got the answer to the damn problem.

Thank you Jesse. You saved my life.

Comment by: igonejack on

igonejack Gravatar```
cd /Library/Developer/CommandLineTools/Packages
open macOS_SDK_headers_for_macOS_xx.pgk
```

Try this if you still missing C headers.

Comment by: michel on

michel GravatarI get :
installer: Error - the package path specified was invalid: '/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg'.

whats wrong?

Comment by: Brian Eng on

Brian Eng GravatarI found a solution that works for me. With 10.14.5, the
'/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg' package is removed.

Instead you have to point it to where the headers are in the Xcode package. In my .bash_profile I added this:
export CPATH="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include"

Comment by: mech on

mech Gravatarhttps://stackoverflow.com/questions/54828310/problems-installing-mysql2-gem

Maybe use this?

bundle config --local build.mysql2 "--with-ldflags=-L/usr/local/opt/openssl/lib"

Comment by: Ben Smith on

Ben Smith GravatarThanks for posting this!

A gotcha I ran into is xcode-select was already installed but without header files. To correct this remove the old command line tools with:
$ (sudo) rm -rf /Library/Developer/CommandLineTools

Then install command line tooks ala:
$ xcode-select --install

Then finally your header file line.

Comment by: Aaron on

Aaron Gravatar@Brian Eng

I love you, Thank you. This worked for me.

Email address will never be publicly visible.

See my Tweet about comment formatting.