在我将我的macos升级到12.2.1之后,当我运行g++ (也和gcc一起)时,我会出现一些奇怪的错误。以下是一个示例:
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>
| ^~~~~~~~~
我尝试了以下解决方案,但到目前为止,它们都没有奏效:
(A)更新xcode:(结果相同)
xcode-select --install
(B)基于建议的here解决方案
export CPATH=/Library/Developer/CommandLineTools/usr/include/c++/v1
这只更改了错误的行号,现在我得到了以下错误消息:
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>
| ^~~~~~~~~
当我搜索这个文件时,我看到这个是:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/wchar.h
供您参考,这是我正在试图编译的简单代码:
#include <iostream>
#include <string>
using namespace std;
int main () {
string str1 = "Hello";
string str3;
// copy str1 into str3
str3 = str1;
cout << "str3 : " << str3 << endl;
}
我的xcode版本是:
Xcode 13.2.1
Build version 13C100
(当我运行gcc时,我遇到了类似的问题,例如:"_stdio.h not“)
关于如何解决这个问题,有什么建议吗?
发布于 2022-04-14 08:30:29
当我的Mac决定自动更新XCode版本时,我就面临着这个问题。我通过更新(重新安装) XCode命令行工具来解决这个问题。
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
https://stackoverflow.com/questions/71363168
复制相似问题