30 Nov 2014

Using distcc to cross compile for Raspberry Pi

My post here is based off the following guide: http://www.openframeworks.cc/setup/raspberrypi/Raspberry-Pi-DISTCC-guide.html

This guide assumes you are familiar with compiling and have all required build tools installed.

Setup your Ubuntu PC

Install the following:

sudo apt-get install distcc

Grab the Raspberry Pi compiler for Linux and remember where you’ve placed it:

git clone https://github.com/raspberrypi/tools.git --depth=1 rpi-tools

I’ll refer to this path as $RPI_TOOLS from now on.

Edit distcc’s config file to have it start on boot with appropriate options.

Edit /etc/default/distcc and change the following:

STARTDISTCC=”true”
ALLOWNETS=”127.0.0.1 192.168.1.0/24” # Change this based on your network config.
ZEROCONF=”true”
LISTNER=”” # Listen on all interfaces

Now edit the PATH variable for distcc so it can find the Raspberry Pi compiler. Replace $RPI_TOOLS with the path to where you cloned the compiler.

PATH=$RPI_TOOLS/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

Start the distcc daemon.

sudo service distcc start

To see the log output of distccd while you’re calling compile at the last step below you can:

tail -f /var/log/distccd.log

On the Raspberry Pi

Install distcc:

sudo apt-get install distcc

Set your distcc hosts on your RPi and add your Ubuntu PC’s ip to the hosts file.

mkdir $HOME/.distcc/
# Add ip to this file
vim $HOME/.distcc/hosts

Now set your make flags to compile with distcc Replace the number 8 below with the number of CPU cores on your distcc server for multiple simultaneous compiling threads.

export MAKEFLAGS=”-j 8 CXX=/usr/lib/distcc/arm-linux-gnueabihf-g++ CC=/usr/lib/distcc/arm-linux-gnueabihf-gcc”

Now it’s as simple as going to the directory of your projects Makefile and calling:

make