Reputation: 83
On Ubuntu I cross-compile a code for the raspberry pi
but when I try to link objects that use standard c libraries I just added
arm-none-eabi-ld -g vectors.o notmain.o bm_bcm2835.o uart.o -T memmap -o notmain.elf
it complains about not finding standard functions
uart.c:135: undefined reference to `strcpy'
uart.c:142: undefined reference to `vsprintf'
so far I tried, adding -lc -lgcc but the linker complains it cannot find them either
arm-none-eabi-ld: cannot find -lc
arm-none-eabi-ld: cannot find -lgcc
I tried adding these flags to the compiler, it compiles fine, but the linker throws the same error
any idea what's going wrong ?
here is the makefile:
ARMGNU ?= arm-none-eabi
AOPS = --warn --fatal-warnings
COPS = -Wall -Werror -O2 -nostdlib -nostartfiles -ffreestanding -g
LDOPS = -g
all : kernel.img
clean :
rm -f *.o
rm -f *.bin
rm -f *.hex
rm -f *.srec
rm -f *.elf
rm -f *.list
rm -f *.img
vectors.o : vectors.s
$(ARMGNU)-as $(AOPS) vectors.s -o vectors.o
uart.o : uart.c
$(ARMGNU)-gcc $(COPS) -c uart.c -o uart.o -lc -lgcc
notmain.o : notmain.c
$(ARMGNU)-gcc $(COPS) -c notmain.c -o notmain.o
notmain.elf : memmap vectors.o notmain.o uart.o
$(ARMGNU)-ld $(LDOPS) vectors.o notmain.o uart.o -T memmap -o notmain.elf
$(ARMGNU)-objdump -D notmain.elf > notmain.list
kernel.img : notmain.elf
$(ARMGNU)-objcopy --srec-forceS3 notmain.elf -O srec notmain.srec
$(ARMGNU)-objcopy notmain.elf -O binary kernel.img
thanks for helping me on this
Upvotes: 2
Views: 880
Reputation: 83
since it's bare metal, there is no sub structure for standards c functions
so here is an example of how to implement bare metal subsystem (heap and such) with newlib
https://www.raspberrypi.org/forums/viewtopic.php?f=72&t=280209&p=1697302#p1697302
Upvotes: 1
Reputation: 33717
If you build with -nostdlib -nostartfiles -ffreestanding
, you are telling the compiler (driver) that you do not want to build for a standard C environment. As a result, standard C functions such as vfprintf
and strcpy
are not available and cannot be used.
Upvotes: 1