[MacOS 10.14.5, Xcode 10.2, CLI Tools, brew clang-9/clang++]
For some reason I am no longer able to build a simple hello world program using
clang++ main.cpp. Instead, I am getting an error:
clang++ main.cpp In file included from main.cpp:9: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iostream:38: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ios:215: In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/iosfwd:90: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/wchar.h:119:15: fatal error: 'wchar.h' file not found #include_next <wchar.h> ^~~~~~~~~
I installed the homebrew's
llvm yesterday because Apple's version does not support the -fopenmp flag correctly. I'm wondering if installing the 2nd version of clang may have changed something I didn't notice and now I can't figure out.
Two things strike me here;
1. why can't
wchar.h find itself in the same directory that it is already at? (Note that it fails on the
#include_next, which is inside the header file it supposedly can't find.)
2. Why is Xcode using
XcodeDefault.xctoolchain showing instead of
I've read countless posts about how to fix this using
xcode-select but unfortunately, it doesn't.
Nonetheless, I have tried
sudo xcode-select /Applications/Xcode.app
and reinstalled my commandline tools, but to no avail.
returns the correct path:
One answer suggested setting an environment variable in my bash profile, but since I didn't need it in the past, I don't like that option.
clang++ main.cpp doesn't work, I am able to build using any of the following:
xcrun clang++ main.cpp /usr/local/opt/llvm/bin/clang++ main.cpp g++ main.cpp (This execute's Apple's version) /usr/local/bin/g++-9 main.cpp I can also build/run from within an Xcode (GUI) project (CLI Tool)