2

After installing clang++ (tried v. 6.0.1 and 7.0) with:
brew install --with-toolchain llvm

very trivial programs result to the following error:

 In file included from test.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>

Command used to compile:

 clang++7() {
    LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"
    CPPFLAGS="-I/usr/local/opt/llvm/include"
    /usr/local/opt/llvm/bin/clang++ -std=c++11 $CPPFLAGS $LDFLAGS $1
 }

Is it possible to use the official clang instead of Apple's version?
With Apple's version, we do not even know which version of LLVM it really is...

  • On a Mac OS X you would normally get `clang` as a part of `XCode`. Any specific reason you are trying it from homebrew? – bobah Oct 03 '18 at 14:23
  • @bobah Which clang version is shipped with Xcode? `Apple LLVM version 10.0.0 (clang-1000.11.45.2)` does not mean a lot to us, does it? I want to try certain C++17 or C++2a features, and I would like to know the exact clang version I am using. – Nick Kanellopoulos Oct 03 '18 at 14:44
  • lmgfy - https://stackoverflow.com/questions/33603027/get-apple-clang-version-and-corresponding-upstream-llvm-version :-) – bobah Oct 03 '18 at 14:56
  • @boobah Scroll down. The solution in this post does not work any more ;) – Nick Kanellopoulos Oct 03 '18 at 15:07
  • damn! but I'd still try the `__cplusplus` and per-feature macros based testing in-code approach if just experimenting opposed to infecting the Mac with "alien" build of the "native" compiler (I use brew for everything apart from clang itself). – bobah Oct 03 '18 at 15:10

2 Answers2

3

It appears that as of Mojave (10.14), Xcode doesn't install system headers in /usr/include anymore. There is a compatibility package that does, but it's not recommended.

Instead, the official solution is for tools to search for headers in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk. That path can be obtained from

xcrun --show-sdk-path

The release notes say

The Command Line Tools package installs the macOS system headers inside the macOS SDK. Software that compiles with the installed tools will search for headers within the macOS SDK provided by either Xcode at:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk

or the Command Line Tools at:

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

depending on which is selected using xcode-select.

If you built clang yourself, this can be achieved by passing the -isysroot option to clang:

clang++ -isysroot "$(xcrun --show-sdk-path)" …

See also: https://github.com/Homebrew/homebrew-core/issues/32765

joki
  • 6,619
  • 2
  • 22
  • 30
1

It works for me to add a -I (minus eye) option to the clang++ command line, pointing to /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include

Kevin S
  • 497
  • 2
  • 10