kriaS
Posts: 6
Joined: Wed Aug 03, 2016 12:11 pm

Cross compilation problem

Mon Aug 15, 2016 1:37 pm

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..

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: Cross compilation problem

Mon Aug 15, 2016 4:59 pm

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 ?

kriaS
Posts: 6
Joined: Wed Aug 03, 2016 12:11 pm

Re: Cross compilation problem

Mon Aug 15, 2016 8:29 pm

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

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: Cross compilation problem

Tue Aug 16, 2016 6:53 am

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

Return to “Troubleshooting”