These instructions assume you have a working cross-compiler on the slave. Please read How to build a GCC 4.7 toolchain for cross-compiling? if you haven't. It is also useful to have make
installed on the master.
Installation
First, we must install distcc
. We shall use the prebuilt packages supplied by the operating systems' package management systems, but you are free to install from source if you want!
Debian
sudo apt-get install distcc
Arch
sudo pacman -S distcc
Configuration
Slave - Debian/Ubuntu
TODO: Is this the same for Arch? If not, how do we configure Arch?
We need to adjust the settings in /etc/default/distcc
. In your favourite editor, open it as root; I ran sudo vim /etc/default/distcc
.
You need to change STARTDISTCC
, ALLOWEDNETS
and LISTENER
. Assuming you have your master and slave are on the same subnet and that subnet is 192.168.0.0/24
, they should be set to
STARTDISTCC="true"
ALLOWEDNETS="192.168.0.0/24"
LISTENER="0.0.0.0"
Furthermore, you should add the path to your compiler. I did this by adding the following line
PATH=$PATH:/home/alex/x-tools/arm-unknown-linux-gnueabi/bin
Note The daemon on the slave will be running as the distccd
user, so ensure the appropriate permissions are configured on your executables; I gave everyone permission to execute.
Run the daemon - it would normally be started at boot - by running
sudo service distcc start
Master - Arch
TODO: Is this the same for Debian? If not, how do we configure Debian?
Open ~/.distcc/hosts
in your favourite text editor and add the IP address of the Slaves. My hosts
file consisted of a single line, which read 192.168.0.22
.
Note It might be a good idea to assign a static IP address to your slave, otherwise you will have to change this file whenever the IP address changes.
Use
All going well, you should be able to use distcc quite simply. For example, to compile hello.c
to hello.o
, run
distcc arm-unknown-linux-gnueabi-gcc -c -o hello.o hello.c
Example: Hello World!
I set up a simple example in my home directory, which consisted of 2 files.
# file: Makefile
hello.o: hello.c
hello: hello.o
file: hello.c
#include <stdio.h>
int main() {
printf("Hello World!\n");
return 0;
}
Running make hello
will compile locally; you should do this as a quick test first. Go on, I'll wait.
Running make hello CC="distcc arm-unknown-linux-gnueabi-gcc"
will run a distributed compilation.
Note The preprocessing and the linking still happens on the RPi.
Debugging
It took me a while to get this working correctly, and the best debugging tool I found was a simple environment variable. If you
export DISTCC_VERBOSE=1
the distcc
client will output loads of useful information.
This is a long post, so any feedback would be gratefully received. I hope I remembered all the steps!
export DISTCC_VERBOSE=1
Thanks for this ! It is what I'm looking for to debbug my distcc toolchain – Nov 27 '12 at 13:06