Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MacOS clang via Homebrew broken under Mojave `wchar.h` [duplicate]

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.

like image 388
rausted Avatar asked Nov 01 '18 15:11

rausted


2 Answers

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.

like image 101
rausted Avatar answered Oct 19 '22 17:10

rausted


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"
like image 1
273K Avatar answered Oct 19 '22 18:10

273K