gcc可以用keil-arm编译器编译的目标文件编译吗?

gcc can compile with object file compiled from keil-arm compiler?

项目芯片:nordic nrf51822 256KB NRF51 SDK 版本:6.1

由于许可问题,我正在将我的项目从 windows keil 转换为 OSX GNU。

我之前的项目中有一些keil-arm编译器生成的.o文件。我没有那些 c 文件。

我尝试编译项目,当它尝试 link 那些 .o 文件时,它会像这样错误退出。

gcc 无法使用从 keil-arm 编译器编译的目标文件进行编译?

... ... ... ... "/usr/local/gcc-arm-none-eabi-4_9-2015q2/bin/arm-none-eabi-gcc" -Xlinker -Map=_build/ble_app_allb_s110_xxaa.map -mcpu=cortex-m0 -mthumb -mabi=aapcs -L ..//Source//templates/gcc/ -Tgcc_nrf51_s110_xxaa.ld _build/main.o _build/Sensor.o _build/Common.o _build/ble_nus.o _build/ble_srv_common.o _build/retarget.o _build/ble_advdata.o _build/app_timer.o _build/simple_uart.o _build/softdevice_handler.o _build/nrf_delay.o _build/pstorage.o _build/ble_conn_params.o _build/system_nrf51.o _build/gcc_startup_nrf51.o adc.o afe4403.o mpu6050.o spi_master2.o twi_hw_master_sd.o -o _build/ble_app_allb_s110_xxaa.out /usr/local/gcc-arm-none-eabi-4_9-2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: error: adc.o: Conflicting CPU architectures 12/0 /usr/local/gcc-arm-none-eabi-4_9-2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: failed to merge target specific data of file adc.o /usr/local/gcc-arm-none-eabi-4_9-2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: error: afe4403.o: Conflicting CPU architectures 12/0 /usr/local/gcc-arm-none-eabi-4_9-2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: failed to merge target specific data of file afe4403.o /usr/local/gcc-arm-none-eabi-4_9-2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: error: mpu6050.o: Conflicting CPU architectures 12/0 /usr/local/gcc-arm-none-eabi-4_9-2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: failed to merge target specific data of file mpu6050.o /usr/local/gcc-arm-none-eabi-4_9-2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: error: spi_master2.o: Conflicting CPU architectures 12/0 /usr/local/gcc-arm-none-eabi-4_9-2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: failed to merge target specific data of file spi_master2.o /usr/local/gcc-arm-none-eabi-4_9-2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: error: twi_hw_master_sd.o: Conflicting CPU architectures 12/0 /usr/local/gcc-arm-none-eabi-4_9-2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: failed to merge target specific data of file twi_hw_master_sd.o /usr/local/gcc-arm-none-eabi-4_9-2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: Dwarf Error: Could not find abbrev number 10. afe4403.o: In function afe_write_reg': ....\RedCarrot_ver2(c)\afe4403.c:(.text+0x0): undefined reference to_printf_percent' /usr/local/gcc-arm-none-eabi-4_9-2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: Dwarf Error: found dwarf version '0', this reader only handles version 2, 3 and 4 information. ....\RedCarrot_ver2(c)\afe4403.c:(.text+0x0): undefined reference to _printf_d' /usr/local/gcc-arm-none-eabi-4_9-2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: Dwarf Error: found dwarf version '11822', this reader only handles version 2, 3 and 4 information. ....\RedCarrot_ver2(c)\afe4403.c:(.text+0x0): undefined reference to_printf_int_dec' /usr/local/gcc-arm-none-eabi-4_9-2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: Dwarf Error: found dwarf version '23598', this reader only handles version 2, 3 and 4 information. afe4403.o: In function heartpulse': ....\RedCarrot_ver2(c)\afe4403.c:(.text+0x7a2): undefined reference to__2sprintf' /usr/local/gcc-arm-none-eabi-4_9-2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: _build/ble_app_allb_s110_xxaa.out: hidden symbol `__2sprintf' isn't defined /usr/local/gcc-arm-none-eabi-4_9-2015q2/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: final link failed: Bad value collect2: error: ld returned 1 exit status make: * [_build/ble_app_allb_s110_xxaa.out] Error 1

简短回答:不,GCC 不能可靠地使用 Keil 生成的 .o 或 .a 文件。

虽然他们可能正在使用 ABI(arm 二进制接口),但 GCC 和 Keil 几乎肯定依赖于不同的 libc 实现,并且可以引用其他工具链不提供的函数。此外,调试信息可能不兼容(请参阅与 DWARF 相关的文本墙中的错误)。最后,虽然 ELF 是一种标准格式,但进入 ELF 文件的很多内容和元数据不一定是标准的,并且每个工具链的处理方式略有不同。

遗憾的是,将所有文件编译到一个工具链中可能对您最有利。

我想报告这是可能的!我已经这样做了并且有效!不过,您需要使用正确的标志来使用 GCC 进行编译。