我实际上正在读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
我试着在谷歌上搜索,并尝试了我找到的解决方案,但都没有成功。有人知道我为什么会犯这个错误吗?
此问题是由测试程序尝试链接libmpc/libmpfr/libgmp时的dyanmic链接库路径问题引起的。
附加在环境变量下面,允许ld链接到正确的so文件:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/mpc/lib/
然后再次尝试构建gcc。
"构建GCC不是一件小事,但如果您仔细遵循说明,它并不困难。许多人在没有正确阅读安装文档的情况下匆忙尝试构建它,并犯下以下一个或多个常见错误:
-
不要跑步/从gcc-src-dir配置(不支持此操作)=>您需要从gcc源目录外部运行configure
-
注意:如果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 Doc
此错误消息可能由多种不同原因引起。找出哪一个的最好方法是查看下面示例中的日志文件"/home/manu/gcc/gcc/i686-pc-linux gnu/libgcc/config.log"。或者在原始海报案例"/mnt/LFS/source/gcc4.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"文件'/home/manu/gcc/gcc/i686-pc-linux gnu/libgcc'。可能有几个测试在配置过程中失败的程序,但其中一些故障不是关键性的。检查文件中的最后一个错误条目。
此错误消息的常见原因是:
GCC构建所需的库丢失,特别是MPFR,GMP和MPC。如果作为共享库安装,则它们必须位于运行时链接器的搜索路径,以便可以找到它们。请按照说明中的答案为什么是我的/配置并使失败?
编译器崩溃。例如,如果出现以下错误"conftest.c:内部编译器错误:",这表示编译器。如果您使用的是未修改版本的GCC,请按照报告错误的过程。
创建交叉编译器时会发生这种情况。
它不是指顶级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编译/安装过程将采用各种include,通过fixincludes
运行它们来解决问题,并根据目标arch进行调整。所需的文件不存在。
参考先决条件页面,我认为这一部分是相关的(重点是我的):
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平台的标头。
问题在于汇编程序,"作为";缺少。首先为目标生成并安装binutils。
在我的情况下是:
export 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