Raspbian Cross Tools

English

Install raspbian/tools

mkdir /opt/raspi; cd /opt/raspi
git clone git://github.com/raspberrypi/tools

,and then edit ~/.bashrc and add following line

export PATH=$PATH:/opt/raspi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin

Check whether all dependent libraries for cross compiler; 

arm-linux-gnueabihf-gcc -v

Loop mount raspbian.img on cross-compile host Linux

mkdir /opt/raspi; cd /opt/raspi
wget https://downloads.raspberrypi.org/raspbian_lite_latest
unzip raspbian_latest
sudo fdisk -l 2016-03-18-raspbian-jessie-lite.img

Device                               Boot  Start     End Sectors  Size Id Type
2016-03-18-raspbian-jessie-lite.img1        8192  131071  122880   60M  c W95 FAT32 (LBA)
2016-03-18-raspbian-jessie-lite.img2      131072 2658303 2527232  1.2G 83 Linux

sudo mkdir /opt/raspi/arm-linux-gnueabihf-rootfs
sudo modprobe loop
sudo mount -o loop,offset=$((1131072*512)) /opt/raspi/2016-18-16-raspbian-jessie-lite.img /opt/raspi/arm-linux-gnueabihf-rootfs

Hello World

Copy /opt/src/vc directory from raspbian;

scp -r r_pi:/opt/src ~/pi

cd ~pi/vc/hello_pi

Edit Makefile.includel; make it like folloing

CC=arm-linux-gnueabihf-gcc
CXX=arm-linux-gnueabihf-gcc

TOP=../../../..

CFLAGS+=-DSTANDALONE -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -DTARGET_POSIX -D_LINUX -fPIC -DPIC -D_REENTRANT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -Wall -g -DHAVE_LIBOPENMAX=2 -DOMX -DOMX_SKIP64BIT -ftree-vectorize -pipe -DUSE_EXTERNAL_OMX -DHAVE_LIBBCM_HOST -DUSE_EXTERNAL_LIBBCM_HOST -DUSE_VCHIQ_ARM -Wno-psabi

LDFLAGS+=-L$(TOP)/vc/lib/ -lGLESv2 -lEGL -lopenmaxil -lbcm_host -lvcos -lvchiq_arm -lpthread -lrt -lm -L../libs/ilclient -L../libs/vgfont

INCLUDES+=-I$(TOP)/vc/include/ -I$(TOP)/vc/include/interface/vcos/pthreads -I$(TOP)/vc/include/interface/vmcs_host/linux -I./ -I../libs/ilclient -I../libs/vgfont

all: $(BIN) $(LIB)

%.o: %.c
        @rm -f $@
        $(CC) $(CFLAGS) $(INCLUDES) -g -c $< -o $@ -Wno-deprecated-declarations

%.o: %.cpp
        @rm -f $@
        $(CXX) $(CFLAGS) $(INCLUDES) -g -c $< -o $@ -Wno-deprecated-declarations

%.bin: $(OBJS)
        $(CC) -o $@ -Wl,--whole-archive $(OBJS) $(LDFLAGS) -Wl,--no-whole-archive -rdynamic

%.a: $(OBJS)
        $(AR) r $@ $^

clean:
        for i in $(OBJS); do (if test -e "$$i"; then ( rm $$i ); fi ); done
        @rm -f $(BIN) $(LIB)

 

And then; 

cd hello_world

make

copy generated hello_world.bin to r_pi and run.

References:

http://www.raspberrypi.org/documentation/linux/kernel/building.md

http://stackoverflow.com/questions/16565308/setting-up-development-environment-for-raspberry-pi

http://hertaville.com/2012/09/28/development-environment-raspberry-pi-cross-compiler/

http://stackoverflow.com/questions/19162072/installing-raspberry-pi-cross-compiler

User login