Gcc 编译“无法计算目标文件的后缀:无法编译”

问题描述 投票:0回答:6

我实际上正在阅读 LFS 书(版本 7.1),并且在第 53 页被阻止。尝试编译 gcc,我尝试了以下命令:

./configure --target=$LFS_TGT --prefix=$LFS/build/gcc-build --disable-nls\
--disable-shared --disable-multilib --disable-decimal-float --disable-threads\
--disable-libmudflap --disable-libssp --disable-libgomp --disable-libquadmath\
--disable-target-libiberty --disable-target-zlib\
--enable-languages=c\
--without-ppl --without-cloog\
--with-mpfr-include=$LFS/source/mpfr/src
--with-mpfr-lib=$LFS/source/mpfr/src/.libs\
--with-gmp-include=/mnt/LFS/source/gmp\
--with-gmp-lib=/mnt/LFS/source/gmp/.libs\
--with-mpc-include=/mnt/LFS/source/mpc/src\
--with-mpc-lib=/mnt/LFS/source/mpc/src/.libs

运行gcc的配置脚本(当然我也已经编译了mpfr、mpc和gmp)。 但一旦我启动:

make -j4

我收到以下错误:

checking for suffix of object files... configure: error: in `/mnt/LFS/source/gcc-4.6.2/x86_64-lfs-linux-gnu/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.
make[1]: *** [configure-target-libgcc] Error 1

我尝试用谷歌搜索并尝试找到的解决方案,但没有任何效果。有谁知道为什么我会收到此错误?

linux gcc compiler-construction linux-from-scratch
6个回答
26
投票

此问题是由于测试程序尝试链接 libmpc/libmpfr/libgmp 时动态链接库路径问题引起的。

附加以下环境变量以允许 ld 链接到正确的 so 文件:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/mpc/lib/

然后再次尝试构建 gcc。


20
投票

“构建 GCC 并不简单,但如果仔细按照说明操作,并不困难。 许多人在没有正确阅读安装文档的情况下就急于尝试构建它,并犯了一个或多个以下常见错误:

  1. 不要从 gcc src 目录运行 ./configure (不支持)=> 你需要从 gcc 源目录之外运行configure

  2. 注意:如果 GCC 动态链接到必备库 (GMP/MPFR/MPC),则无论是在构建 gcc 时还是在使用已安装的编译器时,共享库都必须位于动态链接器的路径 (LD_LIBRARY_PATH) 中。”

简单示例(没有到 GMP/MPFR/MPC 的动态链接):

tar xzf gcc-4.8.0.tar.gz
cd gcc-4.8.0
./contrib/download_prerequisites
cd ..
mkdir objdir
cd objdir
$PWD/../gcc-4.8.0/configure --prefix=/opt/gcc-4.8.0 
make
make install

来源: Advogato 文档 - GNU 文档


6
投票

此错误消息可能由多种不同原因引起。找出哪一个的最佳方法是检查下面示例中的日志文件“/home/manu/gcc/gcc/i686-pc-linux-gnu/libgcc/config.log”。或者在原始海报案例 '/mnt/LFS/source/gcc-4.6.2/x86_64-lfs-linux-gnu/libgcc' 中查找最后一个错误行。

引用 GCC FAQ:http://gcc.gnu.org/wiki/FAQ#configure_suffix

与任何 GNU 项目一样,GCC 使用 GNU 自动工具来 通常根据构建的具体情况配置编译 系统。因此,配置脚本使用小型测试程序 - 通常称为conftest.c - 测试某些功能和/或 功能可用。如果编译这样一个测试程序 失败,您会看到一条错误消息,例如:

 checking for suffix of object files... configure: error: in
 `/home/manu/gcc/gcc/i686-pc-linux-gnu/libgcc': configure: error:
 cannot compute suffix of object files: cannot compile See `config.log'
 for more details. make[2]: *** [configure-stage1-target-libgcc] Error
 1 make[2]: Leaving directory `/home/manu/gcc/gcc'

此错误消息非常具有误导性,并且问题经常出现在 与该消息无关。你必须检查文件 发生错误的目录中的“config.log”。在示例中 上面,您必须检查目录中的“config.log”文件 '/home/manu/gcc/gcc/i686-pc-linux-gnu/libgcc'。可能有几个 测试配置过程中失败的程序,但其中一些 故障并不严重。检查文件中的最后一个错误条目。

此错误消息的常见原因是:

  • 缺少 GCC 构建所需的库,特别是 MPFR, GMP 和 MPC。如果作为共享库安装,它们必须位于 运行时链接器的搜索路径,以便可以找到它们。请遵循 为什么我的 ./configure 和 make 失败?

  • 编译器崩溃了。例如,如果出现如下错误 'conftest.c:内部编译器错误:',这表明存在错误 编译器。如果您使用的是未经修改的 GCC 版本,请遵循 报告错误的程序。


2
投票

创建交叉编译器时会发生这种情况。

不是指顶层

config.log
,而是
$LFS_TGT/libgcc/config.log

对我来说,里面写着:

configure:3566: /foo/gcc/build/./gcc/xgcc -B/foo/gcc/build/./gcc/ -B/opt/gcc-cross-11.1.0/aarch64-none-elf/bin/ -B/opt/gcc-cross-11.1.0/aarch64-none-elf/lib/ -isystem /opt/gcc-cross-11.1.0/aarch64-none-elf/include -isystem /opt/gcc-cross-11.1.0/aarch64-none-elf/sys-include    -o conftest -g -O2   conftest.c  >&5
conftest.c:9:10: fatal error: stdio.h: No such file or directory
    9 | #include <stdio.h>
      |          ^~~~~~~~~
compilation terminated.
configure:3569: $? = 1
configure:3782: checking for suffix of object files
configure:3804: /foo/gcc/build/./gcc/xgcc -B/foo/gcc/build/./gcc/ -B/opt/gcc-cross-11.1.0/aarch64-none-elf/bin/ -B/opt/gcc-cross-11.1.0/aarch64-none-elf/lib/ -isystem /opt/gcc-cross-11.1.0/aarch64-none-elf/include -isystem /opt/gcc-cross-11.1.0/aarch64-none-elf/sys-include    -c -g -O2  conftest.c >&5
/foo/gcc/build/./gcc/as: line 106: exec: -E: invalid option
exec: usage: exec [-cl] [-a name] [command [arguments ...]] [redirection ...]
configure:3808: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "GNU C Runtime Library"
| #define PACKAGE_TARNAME "libgcc"
| #define PACKAGE_VERSION "1.0"
| #define PACKAGE_STRING "GNU C Runtime Library 1.0"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL "http://www.gnu.org/software/libgcc/"
| /* end confdefs.h.  */
| 
| int
| main ()
| {
| 
|   ;
|   return 0;
| }
configure:3822: error: in `/foo/gcc/build/aarch64-none-elf/libgcc':
configure:3824: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details

您的日志文件是否相似?

我相信 gcc 编译/安装过程将采用各种包含,通过

fixincludes
运行它们来修复问题并根据目标架构定制它们。预期的文件不存在。

参考先决条件页面,我相信本节是相关的(强调我的):

C standard library and headers

In order to build GCC, the C standard library and headers must be present for all
target variants for which target libraries will be built (and not only the variant
of the host C++ compiler).

This affects the popular ‘x86_64-pc-linux-gnu’ platform (among other multilib
targets), for which 64-bit (‘x86_64’) and 32-bit (‘i386’) libc headers are usually
packaged separately. If you do a build of a native compiler on ‘x86_64-pc-linux-gnu’,
make sure you either have the 32-bit libc developer package properly installed (the
exact name of the package depends on your distro) or you must build GCC as a 64-bit
only compiler by configuring with the option --disable-multilib. Otherwise, you may
encounter an error such as ‘fatal error: gnu/stubs-32.h: No such file’

我相信解决方案是获取TARGET平台的标头。


1
投票

问题出在汇编器上,缺少“as”。首先为目标构建并安装 binutils。


1
投票

就我而言,是:

导出 LD_LIBRARY_PATH=/usr/mpc-082/lib:/usr/gmp501/lib:/usr/libelf0812/lib

上述每个库都是您安装的附加库的目标,并在末尾附加 /lib。

Example: Lib-MPC:
1) Downloaded onto /usr/src/libmpc-src
2) cd into /usr/src/mpc-082
3) ../configure --prefix=/usr/mpc-082
4) make
5) make install 
6) once installed, verify that you have the new libs installed under /usr/mpc-082-lib
7) add it to your LD_LIBRARY_PATH by doing:
export LD_LIBRARY_PATH=/usr/mpc-082/lib:$LD_LIBDADY_PATH
8) Repeat the same with your LibELF, and LibGMP
9) Go back and compile your GCC, should work after this.

干杯

H

© www.soinside.com 2019 - 2024. All rights reserved.