'fatal error: 'wchar.h' file not found' error with the new macos 11.3 update

2.6k views Asked by At

I'm totally new to c++ (just started learning from scratch yersterday). Today I had this macos update to 11.3 and now when I run my c++ code in clion I get this error,

====================[ Build | untitled | Debug ]================================
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/nibin/CLionProjects/untitled/cmake-build-debug --target untitled -- -j 6
[ 50%] Building CXX object CMakeFiles/untitled.dir/main.cpp.o
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk' [-Wmissing-sysroot]
In file included from /Users/nibin/CLionProjects/untitled/main.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iostream:37:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ios:214:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iosfwd:95:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
              ^~~~~~~~~
1 error generated.
make[3]: *** [CMakeFiles/untitled.dir/main.cpp.o] Error 1
make[2]: *** [CMakeFiles/untitled.dir/all] Error 2
make[1]: *** [CMakeFiles/untitled.dir/rule] Error 2
make: *** [untitled] Error 2

I scoured the internet but didn't understand a word. I did try some of it and got this in my terminal,

➜  ~ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
➜  ~ xcrun --show-sdk-path
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
➜  ~ sudo xcode-select --switch /Library/Developer/CommandLineTools/
Password:
➜  ~ xcrun --show-sdk-path
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

I already have xcode tools and its up to date. I tried one of the solutions which was to change the path but still didn't work. So I just brought back the files to its original location,

➜  ~ sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/
➜  ~ xcrun --show-sdk-path
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

There was another solution which I tried and got an error,

➜  ~ open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
The file /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg does not exist.

I opened the /Library/Developer/CommandLineTools/ and I got this,

➜  ~ cd /Library/Developer/CommandLineTools
➜  CommandLineTools ls
Library SDKs    usr

Some solutions involving clearing the cache "Delete any old CMakeCache.txt in current project and dependencies and rebuild solves the problem." Sorry if this sounds dumb but I'm don't quite understand it. Does it mean we have to delete the entire file CMakeCache.txt or is it just the contents.

1

There are 1 answers

0
user564654 On BEST ANSWER

"We suppose that Tools | CMake | Reset Cache and Reload project should help in this case." (https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000919219-Clion-can-t-compile-because-of-wchar-h-not-found-after-updated-Mojave-in-mac-) That worked for me