简体   繁体   English

安装在 Mac M1 上的 Homebrew g++ 报告了“addend too big for relocation”错误

[英]"addend too big for relocation" error reported by Homebrew g++ installed on Mac M1

I was trying to compile the following program with Homebrew g++ installed on my Mac M1:我试图用 Mac M1 上安装的 Homebrew g++ 编译以下程序:

// name: a.cpp
#include <bits/stdc++.h>
using namespace std;
vector<int> vec[1145140];
int main(){
    return 0;
}

The compiling command is /opt/homebrew/bin/g++-11 a.cpp .编译命令是/opt/homebrew/bin/g++-11 a.cpp Then it reported error as follows:然后报错如下:

/var/folders/qw/n1dkgxj51tb7whl23crnsl880000gn/T//ccrMi6mY.s:431:2: error: addend too big for relocation
        adrp    x0, _vec@PAGE+27483360
        ^
/var/folders/qw/n1dkgxj51tb7whl23crnsl880000gn/T//ccrMi6mY.s:432:2: error: addend too big for relocation
        add     x19, x0, _vec@PAGEOFF+27483360;momd
        ^
/var/folders/qw/n1dkgxj51tb7whl23crnsl880000gn/T//ccrMi6mY.s:432:2: error: fixup value out of range
        add     x19, x0, _vec@PAGEOFF+27483360;momd

I am confused at this since nothing goes wrong when this program gets compiled with clang ( c++ a.cpp ).我对此感到困惑,因为当这个程序用 clang ( c++ a.cpp ) 编译时没有任何问题。 I am wondering whether this is because I forget to add some compiling options, or this is a bug in g++ or something else.我想知道这是因为我忘记添加一些编译选项,还是这是 g++ 或其他东西中的错误。 I will appreciate it if someone can help me.如果有人可以帮助我,我将不胜感激。

Some information that may help:一些可能有帮助的信息:

Output of /opt/homebrew/bin/g++-11 -v : /opt/homebrew/bin/g++-11 -v

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

I can only suggest a temporal solution to this issue.我只能建议这个问题的临时解决方案。 Uninstall Homebrew and download the Intel version under Rosetta 2 instead.卸载 Homebrew 并下载 Rosetta 2 下的 Intel 版本。 Then you can download the Intel version of GCC under Rosetta 2. It works without any problems by me, it seems to me that the M1 version of G++11 still has some bugs.然后你可以在 Rosetta 2 下下载 Intel 版本的 GCC。它在我看来没有任何问题,在我看来 G++11 的 M1 版本仍然有一些错误。

A link about how you can do this: How to run the Homebrew installer under Rosetta 2 on M1 Macbook有关如何执行此操作的链接: How to run the Homebrew installer under Rosetta 2 on M1 Macbook

PS: I encountered an issue when trying to download the Intel version of GCC. PS:我在尝试下载 Intel 版本的 GCC 时遇到了一个问题。 It read that a newer version of the Xcode Command Line Tools is available and I should install them, although I have updated them to the newest version just before trying to download GCC.它读到有新版本的 Xcode 命令行工具可用,我应该安装它们,尽管在尝试下载 GCC 之前我已经将它们更新到最新版本。 This can be solved very easily, just download the noted version (not the newest) of the Xcode CLT from Apple's website, you can find the link in the log that Homebrew gives.这可以很容易地解决,只需从 Apple 的网站下载 Xcode CLT 的注释版本(不是最新的),您可以在 Homebrew 提供的日志中找到链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM