After I upgraded my macos to 12.2.1, I am getting weird errors when I run g++ (also with gcc). Here is a sample:
In file included from /usr/local/Cellar/gcc/10.2.0_2/include/c++/10.2.0/bits/postypes.h:40,
from /usr/local/Cellar/gcc/10.2.0_2/include/c++/10.2.0/iosfwd:40,
from /usr/local/Cellar/gcc/10.2.0_2/include/c++/10.2.0/ios:38,
from /usr/local/Cellar/gcc/10.2.0_2/include/c++/10.2.0/ostream:38,
from /usr/local/Cellar/gcc/10.2.0_2/include/c++/10.2.0/iostream:39,
from try1.cpp:2:
/usr/local/Cellar/gcc/10.2.0_2/include/c++/10.2.0/cwchar:44:10: fatal error: wchar.h: No such file or directory
44 | #include <wchar.h>
| ^~~~~~~~~
I tried the following solutions, but none of them have worked so far:
(A) updated xcode: (same result)
xcode-select --install
(B) based on solution suggested here:
export CPATH=/Library/Developer/CommandLineTools/usr/include/c++/v1
This only changed the line number of the error, now I get this error message:
In file included from /Library/Developer/CommandLineTools/usr/include/c++/v1/iosfwd:95,
from /Library/Developer/CommandLineTools/usr/include/c++/v1/ios:214,
from /Library/Developer/CommandLineTools/usr/include/c++/v1/iostream:37,
from try1.cpp:2:
/Library/Developer/CommandLineTools/usr/include/c++/v1/wchar.h:119:15: fatal error: wchar.h: No such file or directory
119 | #include_next <wchar.h>
| ^~~~~~~~~
When I searched for this file, I saw this is at:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/wchar.h
For your reference, this is the simple code that I am trying to compile:
#include <iostream>
#include <string>
using namespace std;
int main () {
string str1 = "Hello";
string str3;
// copy str1 into str3
str3 = str1;
cout << "str3 : " << str3 << endl;
}
And my xcode version is:
Xcode 13.2.1
Build version 13C100
(I get similar problems when I run gcc, example: "_stdio.h not found")
Any suggestions on how to fix this problem?