【问题标题】:Building 32 bit GCC from source on 64 bit: linking issue在 64 位上从源代码构建 32 位 GCC:链接问题
【发布时间】:2013-08-15 22:42:10
【问题描述】:
/usr/bin/ld: i386:x86-64 architecture of input file `build/gengenrtl.o' is incompatible with i386 output
/usr/bin/ld: i386:x86-64 architecture of input file `build/errors.o' is incompatible with i386 output
/usr/bin/ld: build/gengenrtl.o: file class ELFCLASS64 incompatible with ELFCLASS32
/usr/bin/ld: final link failed: File in wrong format
collect2: error: ld returned 1 exit status

我不知道问题是ld 还是给定的库。

我的配置是

 CC="gcc -m32" \
 CFLAGS="-m32" \
 LD="<path>/bin/32/binutils/2.23.2/bin/ld" \
 LDFLAGS="-m32" \
 ./configure \
 --build=i586-pc-linux-gnu \
 --host=i586-pc-linux-gnu \
 --target=i586-pc-linux-gnu \
 --enable-shared \
 --enable-static \
 --enable-languages=c,c++ \
 --enable-bootstrap \
 --prefix=<path>/bin/32/gcc/i586 \
 --disable-stage1-checking \ 
 --with-gmp=<path>/lib/32/gmp/5.1.2 \
 --with-mpfr=<path>/lib/32/mpfr/3.1.2 \
 --with-mpc=<path>/lib/32/mpc/1.0.1 \
 --with-cloog=<path>/lib/32/cloog/0.18.0 \
 --without-ppl

显然我无法轻易更改 ld 可执行文件,gcc 一直在使用全局系统 /usr/bin/ld 进行编译。

有人可以说这里发生了什么以及如何修复这个链接阶段?

我在 Ubuntu 64 位下,我正在尝试编译 32 位版本的 gcc,当然我已经编译了 32 位的 gmp、mpc、mpfr。

【问题讨论】:

    标签: gcc configuration linker ld


    【解决方案1】:

    我已经解决了类似的问题(Compile gcc on amd64, for running on i686, and target is mips),添加以下命令来制作命令行:

    CC="gcc -m32" CXX="g++ -m32" LDFLAGS=-m32
    

    无需指定 ld 的完整路径。但是您忘记指定使用哪个 C++ 编译器。

    【讨论】:

      【解决方案2】:

      当然你可以使用 64 位操作系统、编译器和链接器从源代码构建 32 位 gcc。问题绝对不是“ld”。

      您做的完全正确:在 CFLAGS 和 LDFLAGS 中指定“-m32”。

      问题在于 build/gengenrtl.obuild/errors.o 似乎是为 64 位(而不是 32 位)构建的。

      建议:

      1) 检查 makefile,并检查您的构建日志。看看这两个文件的构建命令是否有任何“不同”。

      2) 使用“nm”命令验证您的 *.o 目标文件的其余部分是否正确构建为 32 位 - 只有“gengenrtl.o”和“errors.o”(错误地)构建为ELFCLASS64.

      '希望对您有所帮助...

      【讨论】:

      • 如果它们确实是 64 位的?如何使用 32 位 elf 构建该库? ...我不明白这背后的逻辑,如果这个库如此重要,为什么不放一个标志或更多选项?我什至看不到与这些文件相关的标志
      • 还有什么是日志的名称/位置?
      猜你喜欢
      • 1970-01-01
      • 2010-12-01
      • 2019-02-13
      • 2016-12-09
      • 2017-02-18
      • 2020-08-16
      • 2012-04-06
      • 1970-01-01
      • 2017-11-30
      相关资源
      最近更新 更多