Page 1 of 1

Cross compilation problem

Posted: Mon Aug 15, 2016 1:37 pm
by kriaS
hi,
i want to run this c code "world.c" on Raspberry:

Code: Select all

#include <stdio.h>

int main(void)
{
   printf("Hello world!\n");
   return 0;
}
but whenever i try to compile it, it keep giving this error:

Code: Select all

world.o: In function `main':
hello_world/world.c:34: undefined reference to `puts'
i think that there is some library not included, but i don't know what it is..

Re: Cross compilation problem

Posted: Mon Aug 15, 2016 4:59 pm
by mfa298
It would help if you provided a bit more information such as:
  • What platform are you compiling on ?
  • What platform are you compiling for ?
  • What command are you running to do the compilation ?

Re: Cross compilation problem

Posted: Mon Aug 15, 2016 8:29 pm
by kriaS
I'm using Windows 7 - 64bits operating system, compiling for a raspberry pi 1 model b.
i' using YAGARTO as a cross compiler.
this is the makefile i'm using:

Code: Select all

ARMGNU ?= arm-none-eabi

INCLUDEPATH ?= "./h"

COPS = -Wall -O2 -nostdlib -nostartfiles -ffreestanding -mcpu=arm1176jzf-s -I $(INCLUDEPATH)

gcc : kernel.img

OBJS = build/startup.o 

OBJS += build/uart.o
OBJS += build/main.o


OBJS += lib/libc.a
OBJS += lib/libgcc.a 

clean :
	rm -f build/*.o
	rm -f *.bin
	rm -f *.hex
	rm -f *.elf
	rm -f *.list
	rm -f *.img
	rm -f build/*.bc

build/%.o : userApp/%.s
	$(ARMGNU)-gcc $(COPS) -D__ASSEMBLY__ -c -o $@ $<
	
build/%.o : userApp/%.c
	$(ARMGNU)-gcc $(COPS)  -c -o $@ $<


kernel.img : raspberrypi.ld $(OBJS)
	$(ARMGNU)-ld $(OBJS) -T raspberrypi.ld -o ucos_bcm2835.elf 
	$(ARMGNU)-objdump -D ucos_bcm2835.elf > ucos_bcm2835.list
	$(ARMGNU)-objcopy ucos_bcm2835.elf -O ihex ucos_bcm2835.hex
	$(ARMGNU)-objcopy ucos_bcm2835.elf -O binary ucos_bcm2835.bin
	$(ARMGNU)-objcopy ucos_bcm2835.elf -O binary kernel.img

Re: Cross compilation problem

Posted: Tue Aug 16, 2016 6:53 am
by mfa298
From a quick google and the limited information there seems to be about the YAGARTO toolchain it looks like you're trying to compile something that would run bare metal on the pi (i.e. with no operating system). If that's the case you might be better looking in the bare metal part of the forum.

If you're trying to learn C and write stuff that runs under Linux it might be easier to write and compile the code directly on the pi using the gcc tool chain. Bare metal and cross compilation add in a range of other hurdles you have to deal with if you're just trying to learn C