MacOS clang via Homebrew broken under Mojave `wchar.h`

2.2k views Asked by At

Unsurprisingly the new update of OSX Mojave broke my llvm installation in Homebrew, these are the steps I tried:

xcode-select --install # Complained, so I installed commandLineTools from here https://developer.apple.com/download/more/
xcode-select -p /Library/Developer/CommandLineTools
xcode-select --install # Now says installed
sudo xcodebuild -license # Fails, as it says I only have CommandLineTools installed in /Library/Developer/CommandLineTools not xcode

# Try something else (all versions)
brew uninstall --force llvm
brew install llvm # yay v7 how exciting

# Only it still don't work
clang++ -std=c++17 foo.cpp -o f
In file included from foo.cpp:1:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/iostream:38:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/ios:215:
In file included from /usr/local/Cellar/llvm/7.0.0/include/c++/v1/iosfwd:90:
/usr/local/Cellar/llvm/7.0.0/include/c++/v1/wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
              ^~~~~~~~~
1 error generated.

Any ideas? The first half of the things I tried I found online but mostly for older updates of MacOS, maybe Mojave broke things in a new and unpredictable way.

3

There are 3 answers

1
rausted On BEST ANSWER

Here's how I solved it (very dirty but has worked for a long time):

  1. Disabled SIP on my Mac
  2. Symlinked /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include to /usr/include as is expected in POSIX environments.
  3. Re-enabled SIP.

Now I got to make a note to re-do this everytime a new OSX update comes out. This has not broken anything wrt Xcode, clang (from brew) etc so I'll keep it. Be advised though, this might break your stuff.

0
Kris Stern On

I did something dumb but it did fix the problem... Not sure if it will work for your computer though.

Here is what I did: I originally installed c++ using Homebrew on my MacBook on Mojave... so I had to manually install the Xcode CommandLineTools using the installer found at /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg . Then I copied the "c++" folder contents from to folder /Library/Developer/CommandLineTools/usr/include/c++/v1 to the folder where I want the missing file to be, at /usr/local/Cellar/gcc/8.2.0/include/c++/8.2.0 , while replacing files with the same names.

The trick worked, since now the missing file "wchar.h" is right where it should be... I could have simlinked, in hindsight. Cheers!

3
273K On

This is a well known issue of the latest macos. Try to set this environment variable, it must fix this issue.

export LIBCLANG_SYSTEM_INCLUDE_DIR="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include"