致命错误:wchar.h:没有那个文件或目录。

3
当我尝试执行C++代码时,出现了以下错误。
In file included from /usr/local/Cellar/gcc/10.2.0_3/include/c++/10.2.0/bits/postypes.h:40,
                 from /usr/local/Cellar/gcc/10.2.0_3/include/c++/10.2.0/iosfwd:40,
                 from /usr/local/Cellar/gcc/10.2.0_3/include/c++/10.2.0/ios:38,
                 from /usr/local/Cellar/gcc/10.2.0_3/include/c++/10.2.0/ostream:38,
                 from /usr/local/Cellar/gcc/10.2.0_3/include/c++/10.2.0/iostream:39,
                 from main.cpp:1:
/usr/local/Cellar/gcc/10.2.0_3/include/c++/10.2.0/cwchar:44:10: fatal error: wchar.h: No such file or directory
   44 | #include <wchar.h>
      |          ^~~~~~~~~
compilation terminated.

我正在MacOS Big Sur 11.2上使用gcc10编译器。 在更新homebrew或升级到Big Sur 11.2之前,编译器一直正常工作。 运行brew cleanup也可能会导致出现问题。 我已尝试取消链接并重新链接gcc,但没有效果。 如何修复此错误?是否最好删除并重新安装gcc?

你没有为gcc指定stdlib。我敢打赌他们改变了gcc想要解析的共享库的默认位置。类似于stdlib这样的东西。查看这个链接 - Sugar
不,你在编译C++代码时才会出现那个错误。请更新你的问题,展示你使用的确切编译命令。 - Keith Thompson
1个回答

0
这个问题通过更新我的Xcode命令行工具得到了解决。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接