Cross compiling and emulating for Raspberry Pi with Debian Cross-Toolchains and QEMU

Installing the toolchain

Add a .list file in /etc/apt/sources.list.d/ containing : “deb http://emdebian.org/tools/debian jessie main
Update the public key for this repo with ‘curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | sudo apt-key add –
Add armhf as foreign architecture by running ‘sudo dpkg –add-architecture armhf‘.
Check correct install with ‘dpkg –print-foreign-architectures‘    which should show ‘armhf

Run ‘sudo apt-get update‘ and install the toolchain by running ‘sudo apt-get install crossbuild-essential-armhf
/usr/bin should now contain arm-linux-gnueabihf-g++

Emulating armhf with QEMU user-mode emulation

Run ‘sudo apt-get install qemu-user-static

In my case running a cross compiled test c++ program (type hello world) caused dynamic library  load errors…
You can easily fix this by setting an environment variable, export  QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf     (or wherever you installed the toolchain) or by building with static linking.

 

Leave a Reply

Your email address will not be published. Required fields are marked *