sprintf in simple C examples

Questions about the BASICtools and MakeItC
Post Reply
basicchip
Posts: 955
Joined: Fri Oct 19, 2012 2:39 am
Location: Lake Tahoe, CA
Contact:

sprintf in simple C examples

Post by basicchip » Wed Apr 18, 2018 3:51 pm

gcc has a tendency to jump to conclusions about what will need to be linked in later. Often time that conclusion is some part of the linux library that is not compatible with the bare metal environment of embedded ARMs.

One user added an sprintf statement to Hello_World.c and that caused an erroneous linker error

Code: Select all

C:\GIT\armbasic\bin>arm-none-eabi-gcc C:/GIT/armbasic/CMSIS/include/startup.o C:/GIT/armbasic/CMSIS/Palma_world.o C:/GIT/armbasic/CMSIS/include/printf.o C:/GIT/armbasic/CMSIS/include/uart.o C:/GIT/armbasic/CMSIS/include/coridium_pcb.o C:/GIT/armbasic/CMSIS/include/system_LPC5410x.o C:/GIT/armbasic/CMSIS/include/IRQ_cortex.o C:/GIT/armbasic/CMSIS/include/systick.o C:/GIT/armbasic/CMSIS/include/breakpoint.o -Wall  -IC:/GIT/armbasic/CMSIS -IC:/GIT/armbasic/CMSIS/include -IC:/GIT/armbasic/CMSIS/usb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mthumb -funsigned-char -mthumb-interwork -Os -fno-inline -TC:/GIT/armbasic/lib/LPC54102-ROM.ld -Wcast-align -nostartfiles -Xlinker -oC:/GIT/armbasic/CMSIS/Palma_world.elf -Xlinker -M -Xlinker -Map=C:/GIT/armbasic/CMSIS/Palma_world.map -lm 
child process exited abnormally
c:/git/armbasic/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/bin/ld.exe: error: C:/GIT/armbasic/CMSIS/Palma_world.elf uses VFP register arguments, c:/git/armbasic/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/thumb/v7m\libc.a(lib_a-strcpy.o) does not
c:/git/armbasic/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/bin/ld.exe: failed to merge target specific data of file c:/git/armbasic/bin/../lib/gcc/arm-none-eabi/4.6.2/../../../../arm-none-eabi/lib/thumb/v7m\libc.a(lib_a-strcpy.o)
collect2: ld returned 1 exit status
The work around for this was to add your own strcpy routine in the source. We have seen things like this before, and managed to avoid it as we had already been using our own strcpy.

Code: Select all

void strcpy(char * dest, char * src) {
	while (*src) {
		*dest++ = *src++;
	}
	*dest = 0;
}



Post Reply