首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >gcc和g++在我升级到MacOS12.2.1之后停止了工作

gcc和g++在我升级到MacOS12.2.1之后停止了工作
EN

Stack Overflow用户
提问于 2022-03-05 14:47:13
回答 2查看 776关注 0票数 1

在我将我的macos升级到12.2.1之后,当我运行g++ (也和gcc一起)时,我会出现一些奇怪的错误。以下是一个示例:

代码语言:javascript
运行
复制
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:(结果相同)

代码语言:javascript
运行
复制
xcode-select --install

(B)基于建议的here解决方案

代码语言:javascript
运行
复制
export CPATH=/Library/Developer/CommandLineTools/usr/include/c++/v1

这只更改了错误的行号,现在我得到了以下错误消息:

代码语言:javascript
运行
复制
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>
      |               ^~~~~~~~~

当我搜索这个文件时,我看到这个是:

代码语言:javascript
运行
复制
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/wchar.h

供您参考,这是我正在试图编译的简单代码:

代码语言:javascript
运行
复制
#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版本是:

代码语言:javascript
运行
复制
Xcode 13.2.1
Build version 13C100

(当我运行gcc时,我遇到了类似的问题,例如:"_stdio.h not“)

关于如何解决这个问题,有什么建议吗?

EN

Stack Overflow用户

发布于 2022-04-14 08:30:29

当我的Mac决定自动更新XCode版本时,我就面临着这个问题。我通过更新(重新安装) XCode命令行工具来解决这个问题。

代码语言:javascript
运行
复制
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

参考资料:How to update Xcode from command line

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71363168

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档