交叉编译-18:解决arm-none-eabi-gcc交叉编译问题

在项目中使用arm-none-eabi-gcc交叉编译链编译程序时报错:

checking host system type... arm-none-eabi
checking for a BSD-compatible install... /usr/bin/install -c
checking for arm-none-eabi-gcc... /opt/Ambalink/gcc-arm-none-eabi-4_9-2015q3-amba-20160323/bin/arm-none-eabi-gcc
checking whether the C compiler works... no
configure: error: C compiler cannot create executables
See `config.log for more details

通过查看config.log,显示以下错误:

configure:4447: checking whether the C compiler works
configure:4469: /opt/Ambalink/gcc-arm-none-eabi-4_9-2015q3-amba-20160323/bin/arm-none-eabi-gcc -fPIC   conftest.c  >&5
/opt/Ambalink/gcc-arm-none-eabi-4_9-2015q3-amba-20160323/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/lib/libc.a(lib_a-ex    it.o): In function `exit:
exit.c:(.text.exit+0x2c): undefined reference to `_exit
collect2: error: ld returned 1 exit status
configure:4473: $? = 1
configure:4511: result: no
configure: failed program was:

资料显示: 这个工具链发布了两个基于newlib的预构建C库:一个是标准的newlib,另一个是newlib-nano代码大小。为了区分它们,将大小优化的库重命名为: libc.a --> libc_nano.a libg.a --> libg_nano.a 要使用newlib-nano,用户应提供额外的gcc链接时间选项:–specs=nano.specs Nano.specs还处理两个额外的gcc库:libstdc ++ _ s.a和libsupc ++ _ s.a,它们针对代码大小进行了优化。 例如: $ arm-none-eabi-gcc src.c --specs = nano.specs $(OTHER_OPTIONS) 此选项也可以与其他规格选项一起使用:–specs= rdimon.specs。 请注意–specs = nano.specs是一个链接器选项。 确定如果单独编译和链接,则将其包含在链接器选项中。 如果您需要semihosting,请链接如下: $ arm-none-eabi-gcc --specs = rdimon.specs $(OTHER_LINK_OPTIONS) 如果您使用retarget重定位,链接如: $ arm-none-eabi-gcc --specs = nosys.specs $(OTHER_LINK_OPTIONS)

根据查到的以上资料,在CFLAGS选项中添加–specs=nosys.specs参数即可解决以上问题。

注意:使用arm-none-eabi-gcc交叉编译链只能编译ARM 架构的裸机系统(包括 ARM Linux 的 boot、kernel,不适用编译 Linux 应用 Application)

经验分享 程序员 微信小程序 职场和发展