简体   繁体   中英

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

project chip : nordic nrf51822 256KB NRF51 SDK version : 6.1

I'm converting my project to OSX GNU from windows keil because of license problem.

There is some .o files made by keil-arm complier in my previous project. and I don't have those c files.

and I tried compile projects and when it try to link those .o files, it exit by error like this.

gcc can't compile with object file compiled from keil-arm complier?

... ... ... ... "/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-non e-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

Short answer: no, GCC can't use Keil generated .o or .a files reliably.

While they may be using the ABI (arm binary interface), GCC and Keil almost certainly rely on different libc implementations and can have references to functions that the other toolchain doesn't provide. Also, the debug information may not be compatible (see the error in that wall of text related to DWARF). Finally, while ELF is a standard format, a lot of what goes into an ELF file and the metadata isn't necessarily standard, and each toolchain does things slightly differently.

Unfortunately, you're probably best served by compiling all the files in one tool chain.

I want to report that it's possible! I already did this and it works! You need to use the proper flags to compile with GCC though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM