编译ARM目标编译器(arm-none-eabi-gcc)时遭遇configure错误:无法计算目标文件后缀
编译ARM目标编译器(arm-none-eabi-gcc)时遭遇configure错误:无法计算目标文件后缀
问题背景
我正在尝试基于Arch Linux的arm-none-eabi-gcc PKGBUILD来编译面向ARM目标的编译器,已经按照GCC官方文档安装了所有依赖(gmp-6.2.1、mpfr-4.1.0、mpc-1.2.1、isl-0.24),但编译过程中遇到了configure错误,导致编译失败。
核心错误信息
编译时弹出的关键错误如下:
configure error: cannot compute suffix of object files: cannot compile make[3]: Leaving directory '/home/users/truiz/projects/rtos_compiler/build/libcc1' make[2]: Leaving directory '/home/users/truiz/projects/rtos_compiler/build/libcc1' ... configure: error: in `/home/users/truiz/projects/rtos_compiler/build/arm-none-eabi/libgcc': configure: error: cannot compute suffix of object files: cannot compile See `config.log' for more details make[1]: *** [Makefile:13195: configure-target-libgcc] Error 1 make[1]: Leaving directory '/home/users/truiz/projects/rtos_compiler/build' make: *** [Makefile:1035: all] Error 2
从config.log中定位的关键问题
查看config.log后,找到了两个直接触发错误的原因:
- 标准头文件缺失:编译测试程序时找不到
stdio.h
conftest.c:9:10: fatal error: stdio.h: No such file or directory 9 | #include <stdio.h> | ^~~~~~~~~ compilation terminated.
- 汇编器参数不被识别:系统无法处理
-march=armv4t参数
/home/users/truiz/projects/rtos_compiler/build/./gcc/as: 114: exec: -march=armv4t: not found
我使用的编译配置命令
完整的configure和make命令如下:
CFLAGS=${CFLAGS/-Werror=format-security/} CXXFLAGS=${CXXFLAGS/-Werror=format-security/} export CFLAGS_FOR_TARGET='-g -Os -ffunction-sections -fdata-sections' export CXXFLAGS_FOR_TARGET='-g -Os -ffunction-sections -fdata-sections' export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/gmp/lib export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpfr/lib export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mpc/lib export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/isl/lib _target=arm-none-eabi ../gcc/configure \ --target=$_target \ --prefix= \ --with-sysroot=/$_target \ --with-native-system-header-dir=/include \ --libexecdir=/usr/lib \ --enable-languages=c,c++ \ --enable-plugins \ --disable-decimal-float \ --disable-libffi \ --disable-libgomp \ --disable-libmudflap \ --disable-libquadmath \ --disable-libssp \ --disable-libstdcxx-pch \ --disable-nls \ --disable-shared \ --disable-threads \ --disable-tls \ --with-gnu-as \ --with-gnu-ld \ --with-system-zlib \ --with-newlib \ --with-headers=/$_target/include \ --with-python-dir=share/gcc-arm-none-eabi \ --with-gmp=/usr/local/gmp \ --with-mpfr=/usr/local/mpfr \ --with-mpc=/usr/local/mpc \ --with-isl=/usr/local/isl \ --with-libelf \ --enable-gnu-indirect-function \ --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' \ --with-pkgversion='Arch Repository' \ --with-bugurl='https://bugs.archlinux.org/' \ --with-multilib-list=rmprofile make INHIBIT_LIBC_CFLAGS='-DUSE_TM_CLONE_REGISTRY=0'
针对性解决建议
结合错误信息,我整理了几个可能的修复方向:
- 检查sysroot与头文件路径:你指定了
--with-sysroot=/arm-none-eabi和--with-headers=/arm-none-eabi/include,需要确认该路径下存在完整的ARM目标头文件(包括stdio.h)。如果使用newlib,要确保newlib已经正确安装到该sysroot路径,或者在configure阶段让编译器自动处理newlib的构建流程。 - 验证交叉汇编器状态:错误提示
-march=armv4t: not found,说明你的交叉汇编器(arm-none-eabi-as)可能未正确安装,或者版本不支持该参数。可以手动运行arm-none-eabi-as --version检查是否正常,再执行arm-none-eabi-as -march=armv4t -v验证参数是否被识别。 - 确认依赖库路径生效:虽然你设置了LD_LIBRARY_PATH,但可以通过
echo $LD_LIBRARY_PATH确认路径是否正确,也可以尝试在configure命令中通过LDFLAGS直接指定依赖库路径,比如添加LDFLAGS="-L/usr/local/gmp/lib -L/usr/local/mpfr/lib -L/usr/local/mpc/lib -L/usr/local/isl/lib"。 - 对齐Arch PKGBUILD流程:Arch的PKGBUILD可能包含补丁、环境变量设置或依赖处理等你遗漏的步骤,建议仔细对比PKGBUILD中的每一步,确保没有跳过关键操作(比如提前构建或安装newlib到sysroot)。
备注:内容来源于stack exchange,提问作者Mauricio Ruiz




