configure 尝试测试运行一个交叉编译的程序

标签 c gcc cross-compiling autotools configure

我尝试使用 GCC 4.9 为 IBM Blue Gene/Q 编译一些东西。作为依赖项,我需要 gmp(GNU Multi Precision)库,我使用 6.1.1 版。这与 GNU Autotools 一起提供。 奇怪的是,之前曾与 LLVM 合作过。昨天它在中午不工作,但在晚上再次工作,今天不再工作。老实说,我很困惑。

在 Blue Gene/Q 上,您在 IBM PowerPC 740 上编译并让它在 IBM PowerPC A2 处理器上运行。因此你需要使用交叉编译器。我的配置如下:

/homec/hbn28/hbn28e/Sources/gmp-6.1.1/configure \
    --prefix=/homec/hbn28/hbn28e/local-juqueen \
    --host=powerpc64-bgq-linux \
    --build=powerpc64-unknown-linux-gnu \
    --disable-shared \
    --enable-static \
    CC=/bgsys/local/gcc/4.9.3/bin/mpigcc \
    CXX=/bgsys/local/gcc/4.9.3/bin/mpig++ \
    'CFLAGS=-O2 \
    -finline-limit=50000 \
    -Wall \
    -Wpedantic \
    -fmax-errors=1 \
    -fdiagnostics-color=auto \
    -Drestrict=__restrict__ \
    --std=gnu99'

关于 CC_FOR_BUILD 的错误

第一个问题就是这个错误。

/usr/include/stdio.h:34:21: error: stddef.h: No such file or directory

生成的 Makefile 已将 CC 用于一些文件,但随后使用 CC=$(CC_FOR_BUILD) 递归调用自身。默认情况下,它只是设置为 cc,前端编译器对计算后端没有任何好处。所以我将 CC_FOR_BUILD=/bgsys/local/gcc/4.9.3/bin/mpigcc 添加到 configure 标志中。这修复了该错误。

测试交叉编译的二进制文件

然后 configure 脚本进一步运行:

checking build system type... powerpc64-unknown-linux-gnu
checking host system type... powerpc64-bgq-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for powerpc64-bgq-linux-strip... no
checking for strip... strip
configure: WARNING: using cross tools not prefixed with host triplet
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking ABI=mode64
checking whether /bgsys/local/gcc/4.9.3/bin/mpigcc is gcc... yes
checking compiler /bgsys/local/gcc/4.9.3/bin/mpigcc -O2 -finline-limit=50000 -Wall -Wpedantic -fmax-errors=1 -fdiagnostics-color=auto -Drestrict=__restrict__ --std=gnu99 ... yes
checking compiler /bgsys/local/gcc/4.9.3/bin/mpigcc -O2 -finline-limit=50000 -Wall -Wpedantic -fmax-errors=1 -fdiagnostics-color=auto -Drestrict=__restrict__ --std=gnu99 has sizeof(long)==8... yes
checking for powerpc64-bgq-linux-gcc... /bgsys/local/gcc/4.9.3/bin/mpigcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether /bgsys/local/gcc/4.9.3/bin/mpigcc accepts -g... yes
checking for /bgsys/local/gcc/4.9.3/bin/mpigcc option to accept ISO C89... none needed
checking whether /bgsys/local/gcc/4.9.3/bin/mpigcc understands -c and -o together... yes
checking for /bgsys/local/gcc/4.9.3/bin/mpigcc option to accept ISO C99... none needed
checking for /bgsys/local/gcc/4.9.3/bin/mpigcc option to accept ISO Standard C... (cached) none needed
checking how to run the C preprocessor... /bgsys/local/gcc/4.9.3/bin/mpigcc -E
checking build system compiler /bgsys/local/gcc/4.9.3/bin/mpigcc... no
configure: error: Specified CC_FOR_BUILD doesn't seem to work

查看 config.log,它说

configure:9899: checking build system compiler /bgsys/local/gcc/4.9.3/bin/mpigcc
configure:9912: /bgsys/local/gcc/4.9.3/bin/mpigcc conftest.c
configure:9915: $? = 0
/bgsys/source/srcV1R2M4.29840/comm/sys/buildtools/pami/common/bgq/BgqPersonality.h:102: 
/bgsys/source/srcV1R2M4.29840/comm/sys/buildtools/pami/common/bgq/BgqPersonality.h<102>
/homec/hbn28/hbn28e/Sources/gmp-6.1.1/configure: line 10000: 26929 Aborted                 (core dumped) ./a.out
/homec/hbn28/hbn28e/Sources/gmp-6.1.1/configure: line 9917: ./b.out: No such file or directory
/homec/hbn28/hbn28e/Sources/gmp-6.1.1/configure: line 9917: ./a.exe: No such file or directory
/homec/hbn28/hbn28e/Sources/gmp-6.1.1/configure: line 9917: ./a_out.exe: No such file or directory
/homec/hbn28/hbn28e/Sources/gmp-6.1.1/configure: line 9917: ./conftest: No such file or directory
configure:9922: result: no
configure:9927: error: Specified CC_FOR_BUILD doesn't seem to work

似乎使用了正确的编译器。当在前端(我编译的地方)运行程序时,它失败了,因为 BgqPersonality.h 有关于计算后端的特殊信息,程序无法在前端运行。

configure 假定编译器已损坏(对于 前端 来说可能是这样)并停止构建。以前我在 LLVM 上都没有错误,交叉编译工作正常。 configure 甚至说 checking whether we are cross compiling... yes 所以它必须知道情况。也许 CC_FOR_BUILD 用于前端,而 CC 用于计算后端。没有 CC_FOR_BUILD 我无法像上面写的那样编译。

有没有办法正确编译这个交叉?

最佳答案

CC_FOR_BUILD 应该是一个可以为当前 系统编译工具的编译器,而不是您要为其构建二进制文件的系统。该名称来自于 CBUILD 是引用构建发生的系统的名称。

wrote a blog post some time ago这解释了这些系统的命名法以及它们应该如何使用。

关于configure 尝试测试运行一个交叉编译的程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40947759/

相关文章:

c - "redeclaration of symbol with no linkage"在函数作用域上使用时

c - 我的 arm-none-eabi-gcc 在 stm32 上的项目有什么问题?

go - 必须使用 CGO_ENABLED 时会发生什么

c++ - 如何在 tiny210 设备上使用 Qt 应用程序?

c++ - 在 iOS 中使用 Objective-C 背后的理念是什么?为什么不是 C++?

c - 什么时候使用哈希数据结构?

c - 如何使用 .asm 文件中已在 .h 文件中声明和初始化的表

c - 在 C 中实现二进制编码字符的安全编码?

boost - 交叉编译 boost 的问题

c - 在 ubuntu 中使用 gcc 生成特定频率的声音?