gcc编译"无法计算目标文件的后缀:无法编译"

时间:2012-07-16 09:57:14

标签: linux gcc compiler-construction lfs

我实际上正在阅读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

我试图google for it并尝试了我找到的解决方案,但没有任何效果。有谁知道我为什么会收到这个错误?

4 个答案:

答案 0 :(得分:17)

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

在环境变量下方添加以允许 ld 链接到正确的所以文件:

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

然后再次尝试构建gcc。

答案 1 :(得分:10)

“*建立海湾合作委员会并非易事,但如果您仔细遵循指示并不难。 许多人急于尝试构建它而不正确阅读安装文档并犯下一个或多个常见错误:

1)不要从gcc src dir运行./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 Doc - GNU Doc

答案 2 :(得分:3)

此错误消息可能由多种不同原因引起。在下面的示例中,找出哪个是检查日志文件'/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常见问题解答: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'文件   '/家/马努/ GCC / GCC / i686的-PC-Linux的GNU / libgcc的'。可能有几个   测试在配置期间失败的程序,但其中一些   失败是非关键的。检查文件中的最后一个错误条目。

     

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

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

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

  •   

答案 3 :(得分:0)

这是在创建交叉编译器时发生的。

它不是指顶级 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 运行它们以修复问题并根据目标架构定制它们。预期文件不存在。

参考 Prerequisites 页面,我认为此部分是相关的(重点是我的):

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 平台的标头。