【问题标题】:Compiling gcc 4.8.5编译 gcc 4.8.5
【发布时间】:2018-01-05 12:54:05
【问题描述】:

我正在尝试在 Red Hat 6 下编译 gcc 4.8.5。这是我的程序:

tar -xvzf archive.tar.gz

cd gcc-4.8.5

./configure --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release \
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object \
--enable-languages=fortran,c --prefix=/opt/gcc4.8.5

make

然后我得到以下错误:

make  all-am
make[4]: Entering directory `/app/gfortran_build/gcc-4.8.5/host-x86_64-unknown-linux-gnu/lto-plugin'
/bin/sh ./libtool --tag=CC --tag=disable-static  --mode=link gcc -Wall -g  -module -bindir /opt/gcc4.8.5/libexec/gcc/x86_64-unknown-linux-gnu/4.8.5   -o 
liblto_plugin.la -rpath /opt/gcc4.8.5/libexec/gcc/x86_64-unknown-linux-gnu/4.8.5 lto-plugin.lo -Wc,../libiberty/pic/libiberty.a
libtool: link: gcc -shared  .libs/lto-plugin.o    ../libiberty/pic/libiberty.a   -Wl,-soname -Wl,liblto_plugin.so.0 -o .libs/liblto_plugin.so.0.0.0
/usr/bin/ld: ../libiberty/pic/libiberty.a(simple-object-coff.o): relocation R_X86_64_PC32 against undefined symbol `simple_object_set_big_16' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status

我已经阅读了有关 CFLAGS 的信息,但我不会让它发挥作用。

亲切的问候

【问题讨论】:

  • 现在是 2018 年。不要编译 过时 GCC 变体。 GCC 4.8 于 2013 年发布。改为编译最近的 GCC 7,于 2017 年发布。更好的是,使用您的发行版中可用的 gcc
  • 另外,阅读installing GCC。您不能在其源代码树中构建 GCC,您的构建树应该在源代码树之外。你的--prefix 应该是一些/opt/gnu,它不是特定于GCC(然后你将/opt/gnu/bin/ 添加到你的$PATH
  • 不幸的是,一些特定的应用程序需要 gcc 4.8.5。我在这个系统上编译 gcc 的第三个版本。我不明白您的第二条评论:源代码在 /app/gfortran_build/ 下提取,前缀路径为 /opt/gcc4.8.5
  • 不,大多数应用程序并不关心 GCC 的 特定 版本。他们关心ABI。很可能您的应用程序可以使用更新(而非过时)的 GCC 版本进行编译。您应该尝试使用系统的gcc 进行编译;在不太可能的情况下,您确实需要那个 GCC 版本——我认为情况并非如此,除非您需要一些特定的 GCC plugin-,否则您应该(在几段中)解释原因。
  • ... 而 C 程序的 ABI 多年来一直没有改变;对于 C++,它确实很少改变(每隔几年一次)。所以你应该激发你为什么需要那个特定的版本。最后,从源代码构建 GCC 更像是系统管理员任务而不是开发人员任务;那么你最好在Unix&Linux 上询问并提供更多详细信息

标签: linux gcc compiler-errors redhat


【解决方案1】:

GCC 已记录需要在其源代码树的外部构建;查看configuring chapterinstallation 文档:

首先,我们强烈建议将 GCC 构建到与源代码不同的目录中,该目录不位于源代码树中。这就是我们通常构建 GCC 的方式;在srcdir == objdir 仍然可以工作的地方构建,但没有得到广泛的测试;不支持 objdir 是 srcdir 的子目录的构建。

因此您需要根据该规则构建它。因此您的 GCC 构建:

cd gcc-4.8.5
#wrong code from the original question! Don't use that
./configure --enable-bootstrap --enable-shared \
      --enable-threads=posix --enable-checking=release \
      --with-system-zlib --enable-__cxa_atexit \
      --disable-libunwind-exceptions --enable-gnu-unique-object \
      --enable-languages=fortran,c --prefix=/opt/gcc4.8.5

错了;我至少会推荐:

  cd gcc-4.8.5
  mkdir ../_BuildGCC
  cd ../_BuildGCC
  ../gcc-4.8.5/configure --enable-bootstrap --enable-shared \
      --enable-threads=posix --enable-checking=release \
      --with-system-zlib --enable-__cxa_atexit \
      --disable-libunwind-exceptions --enable-gnu-unique-object \
      --enable-languages=fortran,c --prefix=/opt/gnu \
      --program-suffix=-mine

然后,在整个构建之后,可能与

 make -j4

后跟一些mkdir /opt/gnu 具有适当的用户和权限,然后(在同一个_BuildGCC

make install DESTDIR=/tmp/gccinst

最后cp -vr /tmp/gccinst/opt/gnu /opt/gnu 被适当地运行(也许是root....,也许是cp -va

然后您将/opt/gnu/bin/ 添加到您的PATH variable,然后您将使用gcc-mine 来编译您的代码。

顺便说一句,GCC 与 C 程序兼容,因为 ABI 不会改变。 GCC 4.8过时且不受支持。您最好从源代码编译支持的 版本(在gcc.gnu.org 上列出;在2018 年1 月,GCC 7.2GCC 6.4

也许您的特定 Redhat 系统需要将额外/特定的 CFLAGS 附加到您的 configure 命令中。您可以询问您的 Redhat 支持,或尝试在您的 ../gcc-4.8.5/configure 命令末尾附加 CFLAGS=-fPIECFLAGS=-fPIC

最后,您可能会在 gcc-help@gcc.gnu.org 上获得此类帮助,但您最好尝试使用最近的 GCC。很少有 GCC 人记得 4.8 ....

如果您确实需要准确地 GCC 4.8(但我对此表示怀疑),如果需要,您可以购买昂贵的支持(例如从 RedHat 或 AdaCore 人员那里)。

通过谷歌我找到了Installing gcc 4.8 and Linuxbrew on CentOS 6

【讨论】:

  • 您尝试过 GCC 7 吗? IIRC,autoconf 机制多年来一直在改进。
  • 可用的 gcc 包,RHEL6 : gcc53-c++-5.3.0-1.el6.x86_64.rpm, gcc49-c++-4.9.3-1.el6.x86_64.rpm ... + devtoolset 包。见stackoverflow.com/questions/47175706/…
【解决方案2】:

它适用于以下内容:

../gcc-4.8.5/configure CC="/opt/gcc4.5/bin/gcc" --prefix=/opt/gcc4.8.5 --enable-languages=c,c++,fortran --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object

有趣的部分是 CC=...

安装的 gcc 版本是 4.4。使用这个版本,编译失败。

亲切的问候

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-06
    • 2019-01-02
    • 2013-10-06
    • 2013-09-16
    • 1970-01-01
    • 2018-05-02
    • 2020-09-08
    相关资源
    最近更新 更多