代码之家  ›  专栏  ›  技术社区  ›  pwe

编制gcc 4.8.5

  •  -1
  • pwe  · 技术社区  · 7 年前

    我试图在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 ,但我不会让它发挥作用。

    亲切的问候

    2 回复  |  直到 7 年前
        1
  •  1
  •   Basile Starynkevitch    7 年前

    GCC是 记录在案 需要建造 外部 其源树;请参见 configuring chapter its的 installation 文档:

    第一 我们 强烈推荐 该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 适当地运行(可能作为根…,或者 cp -va )

    然后你会加上 /opt/gnu/bin/ 到您的 PATH variable ,您可以使用 gcc-mine 编译代码。

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

    也许您的特定Redhat系统需要额外的/特定的 CFLAGS 待追加 进入您的 configure 命令您可以请求Redhat支持,或尝试附加 CFLAGS=-fPIE CFLAGS=-fPIC 在您的 ../gcc-4.8.5/configure 命令

    最后,你可能会得到这样的帮助 gcc-help@gcc.gnu.org ,但您最好尝试使用最近的GCC。很少有GCC人员记得4.8。。。。

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

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

        2
  •  1
  •   pwe    7 年前

    它与以下各项协同工作:

    ../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。使用此版本,编译失败。

    亲切的问候