LFS GCC-14.2.0 - 第一遍
GCC 依赖于 GMP、MPFR 和 MPC 这三个包。由于宿主发行版未必包含它们,我们将它们和 GCC 一同构建。将它们都解压到 GCC 源码目录中,并重命名解压出的目录,这样 GCC 构建过程就能自动使用它们:
cd $LFS/sources
source lfs_vers
tar xf gcc-${gcc_ver}.tar.xz
cd gcc-${gcc_ver}
tar -xf ../mpfr-${mpfr_ver}.tar.xz
mv -v mpfr-${mpfr_ver} mpfr
tar -xf ../gmp-${gmp_ver}.tar.xz
mv -v gmp-${gmp_ver} gmp
tar -xf ../mpc-${mpc_ver}.tar.gz
mv -v mpc-${mpc_ver} mpc
case $(uname -m) in
x86_64)
sed -e '/m64=/s/lib64/lib/' \
-i.orig gcc/config/i386/t-linux64
;;
esac
mkdir -v build
cd build
../configure \
--target=$LFS_TGT \
--prefix=$LFS/tools \
--with-glibc-version=${glibc_ver} \
--with-sysroot=$LFS \
--with-newlib \
--without-headers \
--enable-default-pie \
--enable-default-ssp \
--disable-nls \
--disable-shared \
--disable-multilib \
--disable-threads \
--disable-libatomic \
--disable-libgomp \
--disable-libquadmath \
--disable-libssp \
--disable-libvtv \
--disable-libstdcxx \
--enable-languages=c,c++
make
make install
注意,刚刚构建的 GCC 安装了若干内部系统头文件。其中的 limits.h 一般来说应该包含对应的系统头文件 limits.h 。也就是 $LFS/usr/include/limits.h 。然而,在构建GCC的时候, $LFS/usr/include/limits.h 还不存在,因此GCC安装的内部头文件是一个不完整的、自给自足的文件,不包含系统头文件提供的扩展特性。这对于构建临时的Glibc已经足够,但是后续工作需要完整的内部头问加。所以必须执行下面的命令创建溢恶完整版本的内部头文件( 否则后续编译M4会出现 M4编译报错(limits.h) 错误):
cd ..
cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
`dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/include/limits.h
异常排查
备注
以下报错仅在我使用了特殊的 在Linux Jail中使用EXT文件系统 实践 LFS 12.4 遇到,之前在物理主机上实践 LFS 12.2 时没有遇到
报错一
我在 在Linux Jail中使用EXT文件系统 环境编译 make 有如下报错:
make[3]: Entering directory '/ext4_lfs/sources/gcc-15.2.0/build/libcc1'
/bin/sh ./libtool --tag=CXX --mode=compile g++ -DHAVE_CONFIG_H -I. ...
...
configure: loading cache ./config.cache
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-lfs-linux-gnu
checking for --enable-version-specific-runtime-libs... no
checking for a BSD-compatible install... /usr/bin/install -c
checking for gawk... gawk
checking for x86_64-lfs-linux-gnu-ar... x86_64-lfs-linux-gnu-ar
checking for x86_64-lfs-linux-gnu-lipo... x86_64-lfs-linux-gnu-lipo
checking for x86_64-lfs-linux-gnu-nm... /ext4_lfs/sources/gcc-15.2.0/build/./gcc/nm
checking for x86_64-lfs-linux-gnu-ranlib... x86_64-lfs-linux-gnu-ranlib
checking for x86_64-lfs-linux-gnu-strip... x86_64-lfs-linux-gnu-strip
checking whether ln -s works... yes
checking for x86_64-lfs-linux-gnu-gcc... /ext4_lfs/sources/gcc-15.2.0/build/./gcc/xgcc -B/ext4_lfs/sources/gcc-15.2.0/build/./gcc/ -B/ext4_lfs/tools/x86_64-lfs-linux-gnu/bin/ -B/ext4_lfs/tools/x86_64-lfs-linux-gnu/lib/ -isystem /ext4_lfs/tools/x86_64-lfs-linux-gnu/include -isystem /ext4_lfs/tools/x86_64-lfs-linux-gnu/sys-include
checking for suffix of object files... configure: error: in `/ext4_lfs/sources/gcc-15.2.0/build/x86_64-lfs-linux-gnu/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details
make[1]: *** [Makefile:14102: configure-target-libgcc] Error 1
make[1]: *** Waiting for unfinished jobs....
/bin/sh ./libtool --tag=CXX --mode=compile g++
...
检查 config.log 发现有如下错误:
...
Supported LTO compression algorithms: zlib zstd
gcc version 11.5.0 20240719 (Red Hat 11.5.0-5) (GCC)
... rest of stderr output deleted ...
configure:4599: $? = 0
configure:4588: gcc -V >&5
gcc: error: unrecognized command-line option '-V'
gcc: fatal error: no input files
compilation terminated.
configure:4599: $? = 1
configure:4588: gcc -qversion >&5
gcc: error: unrecognized command-line option '-qversion'; did you mean '--version'?
gcc: fatal error: no input files
compilation terminated.
...
我手工检查:
11.5.0lfs:/ext4_lfs/sources/gcc-15.2.0/build$ gcc --version
gcc (GCC) 11.5.0 20240719 (Red Hat 11.5.0-5)
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
lfs:/ext4_lfs/sources/gcc-15.2.0/build$ gcc -V
gcc: error: unrecognized command-line option '-V'
gcc: fatal error: no input files
compilation terminated.
我最初以为是 gcc 版本过低导致不兼容 -V 参数,但是实践上我对比了不同的 Ubuntu Linux Alpine Linux 等最新版本gcc都是同样情况。然后仔细查看了 gcc --help 发现 -V 参数实际上是:
-v Display the programs invoked by the compiler.
那么为何会出现上述报错?
我没有找到问题原因,看起来似乎 Rocky Linux 9系统有什么地方和我之前使用的 Fedora 系统有所区别。我准备将 FreeBSD Linux Jail 切换到 Fedora 系统再次尝试