gpt4 book ai didi

c++ - 在Mac mojave上安装的gcc和g++无法正常工作(简装)

转载 作者:行者123 更新时间:2023-12-02 10:38:20 26 4
gpt4 key购买 nike

我在Mac OS mojave上通过brew安装了gcc,但gcc和g++均无法正常工作。

我尝试通过g++在简单代码下进行编译,但收到错误消息。

默认情况下,可以使用clang正确编译该程序,
所以我想知道是否有任何库链接错误。
但是我不确定。

在gcc的情况下,我遇到了同样的错误。

#include <iostream>
using namespace std;

int main(){
int i;
cin >> i;
cout << i * 2 + 1 << endl;
}

ld: warning: ignoring file /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd, file was built for unsupported file format ( 0x2D 0x2D 0x2D 0x20 0x21 0x74 0x61 0x70 0x69 0x2D 0x74 0x62 0x64 0x2D 0x76 0x33 ) which is not the architecture being linked (x86_64): /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd Undefined symbols for architecture x86_64: "___cxa_atexit", referenced from: __static_initialization_and_destruction_0(int, int) in ccEBCemd.o ld: symbol(s) not found for architecture x86_64 collect2: error: ld returned 1 exit status



g++ -v说

Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/9.2.0_1/libexec/gcc/x86_64-apple-darwin18/9.2.0/lto-wrapper Target: x86_64-apple-darwin18 Configured with: ../configure --build=x86_64-apple-darwin18 --prefix=/usr/local/Cellar/gcc/9.2.0_1 --libdir=/usr/local/Cellar/gcc/9.2.0_1/lib/gcc/9 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-9 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --with-pkgversion='Homebrew GCC 9.2.0_1' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk Thread model: posix gcc version 9.2.0 (Homebrew GCC 9.2.0_1) `



谢谢。

最佳答案

总之,通过更新Xcode解决了该错误。
感谢您的帮助。

如您所言,我尝试g++ --sysroot=/ -o test test.cpp
然后我遇到了一个新的错误,例如

fatal error: wchar.h: No such file or directory #include ^~~~~~~~~



我也尝试编译只有 int main(){}而没有任何库的代码。然后成功了。

由此,我了解到标准库中存在一个问题。
有时在 Can't compile C program on a Mac after upgrade to Mojave中讨论了此问题。

无论如何,解决此类问题的方法似乎是更新或重新安装Xcode或gcc。

谢谢!

关于c++ - 在Mac mojave上安装的gcc和g++无法正常工作(简装),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58643485/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com