Euphorbium
Euphorbium

Reputation: 1277

'wchar.h' file not found

I know about this question: macOS 'wchar.h' File Not Found but it did not help me. I've tried reinstalling xcode, reinstalling command line tools, restarting the system. wchar.h file is in place, but the compiler does not manage to find it. What else could I try? Maybe it is sysroot related? Any way to fix that?

macbooks-MacBook-Pro:Rack euphorbium$ sudo make
c++ -Iinclude -Idep/include -Idep/lib/libzip/include -DVERSION=dev -MMD -O3 -march=core2 -ffast-math -g -Wall -DARCH_MAC -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk -mmacosx-version-min=10.7 -DAPPLE -stdlib=libc++ -std=c++11 -stdlib=libc++ -c -o build/src/app.cpp.o src/app.cpp
clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk' [-Wmissing-sysroot]
In file included from src/app.cpp:1:
In file included from include/app.hpp:2:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/vector:265:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/iosfwd:90:
/Library/Developer/CommandLineTools/usr/include/c++/v1/wchar.h:119:15: fatal error: 
      'wchar.h' file not found
#include_next <wchar.h>
              ^~~~~~~~~
1 error generated.
make: *** [build/src/app.cpp.o] Error 1

since wchar.h exists both in the xcode app, and in the /Library/Developer/CommandLineTools I think that it looks for it in some completely unrelated folder.

Upvotes: 17

Views: 22582

Answers (9)

Bishal Baaniya
Bishal Baaniya

Reputation: 41

If you are using CLion, follow these steps :

  1. Click on CMake at the bottom center of your IDE
  2. Click on the Settings Gear Icon at the left
  3. Click on Reset Cache and Reload Project

Took me 3 hours to find this solution.

FYI this project was running fine on Bug Sur 11.3 but failed to build after I upgraded to Big Sur 11.4

Upvotes: 2

杨文明
杨文明

Reputation: 9

For my case, this problem result from that MacOS changes the headers's path.

Check this note: MacOS release note. So the solution is to make the compiler can find those headers. My macOS version is Catalina 10.15, and XCode Version 12.4. For this version, it seems that /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg is not provided anymore and thus the sulotions above do not work for me.

This method saved my night: Fixing C++ compilation bugs for the MacOS Catalina upgrade. Note that if you follow its steps and errors that some global symbols are not found arise, do not modify the LIBRARY_PATH as it says.

Upvotes: 0

puio
puio

Reputation: 1278

Set an environment variable

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

and reopen Terminal. This solves the header not found issue.

To see where the compiler finds headers, run with -v

 clang -v test.c

Upvotes: 0

NeilXu
NeilXu

Reputation: 31

My system is macOS Mojave, and I've fixed this problem by running this command line:

open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

Upvotes: 3

ssh
ssh

Reputation: 399

For any one struggling with this on MacOSX Mojave this answer solves it. In short:

  • Go to the terminal and run open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg This will bring up the prompt to install Xcode tools.
  • After that's done got to the terminal and run sudo xcode-select -s /Library/Developer/CommandLineTools

Upvotes: 9

Kris Stern
Kris Stern

Reputation: 1340

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... Your settings is probably not the same, however, I am afraid.

Upvotes: 1

alain
alain

Reputation: 114

I've got the same problem. I was able to fix it by using a symbolic link. This is what I made :

cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
sudo ln -s MacOSX.sdk MacOSX10.07.sdk  

Then enter your root password.

NB: you have to adapt the last line with required sdk.

Upvotes: 9

Kamyar
Kamyar

Reputation: 321

I had the same problem after upgrading to macOS High Sierra. A project which was compiling before stopped working with this error. In my case, the project files had been generated by the CMake application. The solution was to run CMake, 'Delete Cache', and 'Configure' the project again. This corrected the sysroot directory reference in the make files to point to the new SDK and the error was resolved.

Upvotes: 18

Euphorbium
Euphorbium

Reputation: 1277

It was caused by incorrect sysroot, (set for an older mac os version) set in makefiles.

Upvotes: 2

Related Questions