Raspberry Pi cross compilation


Download the VM from russelldavis vm

Use the v.0.8 or newer (if there is one).

I am using the wheezy beta version for Raspberry Pi and need a cross compilation environment to build very large projects.

The instructions that follow describe how to build a new toolchain and to setup an additional scratchbox2 environment for wheezy and the toolchain.

Install some missing packages we will need later:
apt-get install bison
apt-get install flex
apt-get install subversion
apt-get install gperf
apt-get --fix-missing install texinfo
apt-get install libtool
apt-get install schroot

Build a cross compiler toolchain for wheezy (gcc 4.6.x)

Download crosstool-ng
Create a directory for crosstools.
cd into the directory and unpack the downloaded file.
make install
/usr/local/bin/ct-ng menuconfig
The configuration I used is:
  • Paths and Misc options: Enable 'Try features marked as Experimental'
  • Target Options->Target architecture: arm
  • Target Options->Floating point:  softfp
  • Operating System->Target OS: Linux
  • Operating System->Linux Kernel Version:3.3.4 (should match the kernel version if you are building a kernel or device driver).
  • Binary Utilities->binutils version: 2.21.1a or latest that is not experimental
  • C Compiler->Enable Show Linaro version (Experimental) option
  • C Compiler->gcc version: linario-4.6.2012.04
  • C Compiler->Select C++ compiler
  • Companion tools->Select Build some companion tools
  • Companion tools-> select all the tools
Now build the toolchain (you might need to have lunch and tea ;>> while you wait):
/usr/local/bin/ct-ng build

Create a new rootfs for wheezy

Download debootstrap from packages.debian.org.
Create a directory for debootstrap and cd to it.
Unpack the download.
export DEBOOTSTRAP_DIR=`pwd`
./debootstrap --verbose --include=apt --arch armel \
 --foreign wheezy /home/raspberrypi/Development/wheezy \
I do not seem to be able to install the apt package. So this is just for a small base system. We will come back to this.

Change the permissions.
cd /home/raspberrypi/Development/wheezy
chmod -R 777 *

Configure scratchbox to use new rootfs and compiler chain.

Change directory to wheezy.
sb2-init wheezy /home/raspberrypi/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc
sb2-config -d wheezy
Note: we pass the path to the gcc compiler... to sb2-init

Test the setup

Test the compiler is the one you want to use:
sb2 gcc -v
Test the compiler works:
sb2 gcc test.c
What test.c contains:
raspberrypi@raspberrypi-developer:~/Development$ cat test.c

int main(int argc, char*argv[])
  return 1;
Test the exe produced works:
raspberrypi@raspberrypi-developer:~/Development$ sb2 ./a.out
raspberrypi@raspberrypi-developer:~/Development$ file ./a.out
./a.out: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.3.4, not stripped
The ultimate test is to run this on your raspberrypi.

Update the rootfs

The rootfs is minimal you will need to copy from you raspberrypi boot card the necessary include and lib folders.

I upgraded by raspberrypi before I copied off what I needed:
apt-get update
apt-get upgrade
apt-get --fix-missing install xorg-dev
You may need to answer some questions while doing the updates.
When it's all finished reboot and check the raspi-config settings and enable CTRL-ALT-BACKSPACE.
Copy off the necessary include and lib folders and put them in the same place in your wheezy rootfs


The X11 libraries are not in the usual directory. They can be found here:
Additionally the base library names are missing so you will need to do:
ln -s libX11.so.6 libX11.so

Issues To watch out for

If you copy all the libraries off your wheezy image you may get link errors with libc. Try moving the one in usr/lib to a new name.