[メモ] fatal error: 'wchar.h' file not found


ビルドエラーの修正履歴

macOSで今までビルドできていたプログラムがビルドできなくなって、以下のようなビルドエラーが発生する時のメモ。CommandLineToolsのSDKが変わってしまったらしい。

#include_next <wchar.h>
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/wchar.h:              ^~~~~~~~~118
:15: fatal error: 'wchar.h' file not found

環境

macOS Catalina (10.15.7)
XCode12.3
Apple clang version 12.0.0 (clang-1200.0.32.28)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

作業

https://github.com/phracker/MacOSX-SDKs/releases からMacOSX10.15.sdk.tar.xzをダウンロードして、
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs にコピー。

cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
sudo tar xvf MacOSX10.15.sdk.tar.xz
sudo rm MacOSX10.15.sdk.tar.xz

MacOSX.sdkのリンク修正

ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk'

以上で再びビルドできるようになった。