autotools,如果无法找到交叉编译器,如何失败

时间:2013-10-31 14:16:29

标签: c autotools

我使用autoconf / automake制作了一个小项目。

该项目旨在进行本地编译和交叉编译,例如:就这样:

./configure --host=arm-none-eabi

这很好用。但有一个问题是如果没有安装交叉编译器,配置的脚本会忽略它,并且很高兴使用安装的默认编译器来编译它,例如。

./configure --host=arm-none-eabi
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for arm-none-eabi-strip... no
checking for strip... strip
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking whether make sets $(MAKE)... (cached) yes
checking for arm-none-eabi-gcc... no
checking for gcc... gcc
checking whether the C compiler works... yes

这里没有找到arm-none-eabi-gcc。但它找到了本机gcc,并继续使用本机编译器。

如果我使用--host = XXXX请求交叉编译并且无法找到编译器,我可以在configure.ac中放置配置脚本停止和错误输出吗?

1 个答案:

答案 0 :(得分:2)

指定--host=<host-type>时,此值与运行config.guess脚本的结果不同,autoconf进入cross-compilation模式。具体而言,变量cross_compiling设置为yes

如果配置脚本处于“交叉编译”模式,则它无法运行任何生成的可执行文件,因此无法判断生成的二进制文件是否为有效的“主机”二进制文件。据推测,文件magic值的大型数据库可能能够判断是否已生成有效的主机二进制文件。尽管在自动工具中内置了几十年的经验,但仍有一些组合问题无法跟上所有可能的架构和ABI。

autoconf C编译器tests检查编译器(即$CC)是否可以构建可执行文件。如果编译器没有以主机三元组为前缀(例如autoconf),arm-none-eabi-gcc可能会发出警告,但如果找到有效的编译器(例如本机gcc则不会'失败'

因此,使用正确的编译器确保交叉编译的唯一方法是指定编译器:

./configure --host=arm-none-eabi CC="arm-none-eabi-gcc"

如果此编译器无法构建可执行文件,则configure脚本将失败。