gcc 和 g++升级到 macos 12.2.1 后停止工作

发布于 2025-01-12 01:36:47 字数 2107 浏览 2 评论 0原文

将 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)基于建议的解决方案 此处

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 found”)

有关如何解决此问题的任何建议吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忆依然 2025-01-19 01:36:47

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

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

参考:如何从命令行更新 Xcode

I just faced that when my Mac decided to auto update the XCode version. I solve it by updating (reinstalling) XCode command line tools.

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

Reference: How to update Xcode from command line

无悔心 2025-01-19 01:36:47

我的是12.2.1。我创建了一个非常简单的文件:

#include <wchar.h>

int main() {
}

我编译了:

g++ Foo.cpp --std=c++17 -o Foo

它编译没有任何错误。对我来说,这是一台全新的机器(我昨天确实得到了它)。我没有包含您列表中的任何环境变量。

我在 /usr/bin/g++ 中找到了 g++。然而,它不是 gnu 编译器。这是苹果的叮当声。 (g++——版本)。铿锵版本 13.0.0。

如果你升级并做了 xcode 的事情,那么你可能会处于一种奇怪的模式,你的路径中有真正的 g++,但它指向奇怪的狗屎。如果您需要 g++ 而不是 clang,那么可以删除并重新安装。

I'm on 12.2.1. I created a very simple file:

#include <wchar.h>

int main() {
}

And I compiled with:

g++ Foo.cpp --std=c++17 -o Foo

It compiled without any errors. For me, this is a brand new machine (I literally got it yesterday). I have none of the env vars included you list.

I get the g++ in /usr/bin/g++. However, it's not the gnu compiler. It's Apple's clang. (g++ --version). clang version 13.0.0.

If you upgraded and did the xcode thing, then you might be in a weird mode that you have real g++ in your path, but it's pointing to weird shit. If you need g++ and not clang, then maybe remove and reinstall.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文