76

Under OS X 10.9.5 using XCode 6.0.1 I am running into the following issue when I try to run make from the terminal:

fatal error: 'wchar.h' file not found

This issue was not happening prior to a recent upgrade to Mavericks.

Cameron Lowell Palmer
  • 21,528
  • 7
  • 125
  • 126
ssell
  • 6,429
  • 2
  • 34
  • 49
  • 2
    Hello from Google. [This is the answer you're probably looking for](https://stackoverflow.com/a/52530212/510036) if you upgraded to Mojave recently. – Qix - MONICA WAS MISTREATED Jan 29 '19 at 20:00
  • 1
    Possible duplicate of [Can't compile C program on a Mac after upgrade to Mojave](https://stackoverflow.com/questions/52509602/cant-compile-c-program-on-a-mac-after-upgrade-to-mojave) – arghtype Jan 29 '19 at 21:42

10 Answers10

96

First ensure that the latest XCode is installed. Next, we need to install/fix/update Command Line Tools. To do so, run

xcode-select --install

Previously, XCode expected it's active developer directory to be located at

/Applications/Xcode.app/Contents/Developer/

but the latest Command Line Tools is installed to

/Library/Developer/CommandLineTools/

so we need to switch where XCode is looking. To do so, run

sudo xcode-select --switch /Library/Developer/CommandLineTools/

And that should be it. These steps solved the issue for myself and two coworkers.

ssell
  • 6,429
  • 2
  • 34
  • 49
  • 27
    Does not work for me. I can see that wchar.h file is located on /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/wchar.h and it should be found. There is no such file in command line tools folder (and deeper there) – Euphorbium Sep 21 '17 at 09:52
  • 5
    I had the same problem, but with string.h The solution for me was to delete "by hand" (with Finder) all output directories. The problem was that some old output files referenced out-of-date XCode paths. After I deleted all the output files, the problem was solved – peter70 Jun 18 '18 at 14:10
  • @peter70 Where are the output files you're referring to located? I encountered this issue with a Qt build, and I have no idea where to start looking for those output files. – Piotr99 Sep 26 '18 at 09:52
  • 1
    @Piotr99 If I remember correctly, they were the normal output files, in the output directory I specified (in Qt Projects Build Settings) – peter70 Oct 04 '18 at 06:57
  • @peter70: Thank you for your comment, it was the same for me. – Violet Giraffe Jul 11 '23 at 12:11
54
  • My error was similar to yours which said string.h not found, I solved it by running this command:
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

I think that the problem is that for macOS Mojave users, the headers are no longer installed under /usr/include by default.

Yupeng Tang
  • 663
  • 6
  • 7
14

Adding on ssell's post and peter70's comment, I also still had issues after installing xcode command line tools again, and switching the xcode active developer directory. I was using CMake, and so deleted the debug/release folders which had existing Makefiles referencing out-of-date locations on Mojave. So for future problem resolving, after running the commands from ssell's post:

xcode-select --install

sudo xcode-select --switch /Library/Developer/CommandLineTools/

I believe if you've installed the command line tools by installing Xcode itself, you may also need to agree to the licence with sudo xcodebuild --license. I don't think this is necessary if you used the prior xcode-select command.

Then also delete generated build scripts. If using CMake, delete the cmake-build-debug and cmake-build-release directories (your names may vary)

Josh
  • 149
  • 1
  • 4
13

Deleting all the generated files and restarted the compilation worked for me. It was suggested in this link:

https://discourse.brew.sh/t/solved-scan-build-from-llvm-7-0-seems-broken-on-macos-mojave/3151/14

  • 1
    Works for me! (Here is my case: seems that I firstly let cmake generated those files (months ago), then update the mac version, then try to make / cmake again.) – ch271828n Dec 20 '20 at 03:11
  • It works for qt6, and I deleted pro.user file. – crownZ Jul 20 '22 at 12:42
  • Regenerating from CMake and then ninja was not enough. Deleting the CMake-generated files also worked for me. I guess mine were too old. I wish CMake were smart enough to delete the old cache. – Daniel Ryan Jan 25 '23 at 00:59
5

Deleting all the generated files, like @Alfredo Morales Pinzón. If you use cmake, so you need to delete the work dictionary which is "cmake-build-debug" and regenerated the "cmake-build-debug".

yongyu wu
  • 99
  • 1
  • 2
  • Works for me! (Here is my case: seems that I firstly let cmake generated those files (months ago), then update the mac version, then try to make / cmake again.) – ch271828n Dec 20 '20 at 03:11
1

xcode-select --install worked for me.

additionally if you're using visual studio code and your intellisense acts weird -

  1. make a folder called .vscode in your project root.
  2. install vscode extension call C/C++ by microsoft
  3. create the c_cpp_properties.json file and paste the below contents

project_dir > .vscode > c_cpp_properties.json

{
    "configurations": [
      {
        "name": "macOS",
        "includePath": ["${workspaceFolder}/**"],
        "defines": [],
        "macFrameworkPath": ["/System/Library/Frameworks", "/Library/Frameworks"],
        "compilerPath": "/usr/bin/clang",
        "cStandard": "c11",
        "cppStandard": "c++17",
        "intelliSenseMode": "${default}"
      }
    ],
    "version": 4
}
auxeon
  • 15
  • 3
0

Make sure, you update all symbols files which have references to the wchar after updating xcode. For me full cleaning build directory has worked

voltento
  • 833
  • 10
  • 26
0

If it happened after update Xcode you need (Apple WTF?) download and install Command Line Tools for Xcode manually from https://developer.apple.com/download/more/?=for%20Xcode

Or using terminal

xcode-select --install

Restart and maybe clean build cache (delete cmake-build-debug) before run your project.

I guess it's needed every time after update Xcode for all major program update

korytoff
  • 142
  • 5
0

The issue is that the path of compiler gets changed after update or other advancement maybe xcode reinstallment. I have tried everything that was given on every site sadly none worked.

I figured out that many issues cause this .

But then what worked for me is unlinking gcc. I had also installed gcc from homebrew earlier. Just unlinking it worked for me. So if you are also one of the few who has installed gcc from homebrew then

brew unlink gcc

should be sufficient to get it off your default path, so you'll be back to Xcode's default gcc (assuming you have that installed).

0

I'm on MacOS Ventura. I've been struggling with this for hours. Setting symbolic links was the only solution that worked for me. Here is it https://stackoverflow.com/a/58349403/11822798.

miso01
  • 414
  • 6
  • 12