- 
                Notifications
    
You must be signed in to change notification settings  - Fork 11
 
Raspberry pi cross compiling guide
This guide is recommended for developers who are working on the openFrameworks core or projects that have lots of source files. For some users, the speed of a native Raspberry Pi build (as outlined in our getting started guide), might be just fine. For those who need speed, see below!
distcc is a program that enables a single "master" computer (the Raspberry Pi in our case) to distribute its compiling load to other "helper" machines (a multi-core Ubuntu Linux machine) over the network.  In standard mode, source files are preprocessed on the Raspberry Pi, compressed and sent to the helper machine for compiling.  The helper machine, which in this case is running an arm-compatible cross-compiler, compiles the object files (.o files) and sends them back to the Raspberry Pi.  Once the Raspberry Pi has received all of the object files, it will then link them into a library or executable.
It is also possible to distribute preprocessing using distcc-pump, but this feature is not explored below.
Note: The guide below was developed on OS X running 10.8.2. The Ubuntu "helper" machine is Ubuntu 12.04 64-bit running inside Parallels 8. Networking for the Ubuntu instance is set to BRIDGED allowing it to be accessible to the Raspberry Pi on the same network.
- 
On the Ubuntu "helper" Machine
- Install dependencies
sudo apt-get install mercurial bison flex texinfo automakesudo apt-get install build-essential libncurses-dev libtool gawk gperf
 - Install 
crosstool-ng- 
mkdir -p $HOME/x-tools/src- Note: You can put it elsewhere, but this guide will use this location.
 
 cd $HOME/x-tools/src- 
wget http://crosstool-ng.org/download/crosstool-ng/crosstool-ng-1.17.0.tar.bz2- Note: We are using a recent stable build, rather than the bleeding edge git version.
 
 tar xvf crosstool-ng-1.17.0.tar.bz2mkdir $HOME/x-tools/crosstool-ngcd $HOME/x-tools/src/crosstool-ng-1.17.0/./bootstrap./configure --prefix=$HOME/x-tools/crosstool-ngmakemake install- (optional) 
sudo cp ct-ng.comp /etc/bash_completion.d/ - Add the following to your 
$HOME/.profilefileexport PATH=$HOME/x-tools/crosstool-ng/bin:$PATH
 - Load the new paths
source $HOME/.profile
 
 - 
 - Create a cross-compiler toolchain for the Raspberry Pi
mkdir $HOME/cross-raspcd $HOME/cross-rasp- You can configure your cross-compiler by hand, or you can use this existing configuration:
- 
curl -s http://pastebin.com/raw.php?i=Rh6tvh32 | tr -d '\r' > .config- Note: For some reason, both curl and wget were adding 
\rline endings.tr -d '\r'strips those. 
 - Note: For some reason, both curl and wget were adding 
 
 - 
 - 
ct-ng build- Wait for a few minutes while everything downloads and builds ...
 
 
 - Now create a distcc "masquerade directory" so that 
distccwill present ourarmgcc, etc as the default gcc.cd $HOME/x-tools/arm-unknown-linux-gnueabi/bincurl -s http://pastebin.com/raw.php?i=NR7qiJA4 | tr -d '\r' > linkchmod +x link./link
 - Install and configure 
distccon the Ubuntu Helper machinesudo apt-get install distcc- Edit 
/etc/default/distcc(e.g.sudo vi /etc/default/distcc)- Change 
STARTDISTCC="false"toSTARTDISTCC="true" - Change 
ALLOWEDNETS="127.0.0.1"to include the network IP addresses of your Raspberry Pis- Note: Addresses use CIDR notation.  To allow your 
localhostAND IP addresses in the range192.168.0.0-192.168.1.255use thisALLOWEDNETS="127.0.0.1 192.168.0.0/23. - Note: If you want help with CIDR notation, you can use the calculator here http://www.subnet-calculator.com/cidr.php.
 
 - Note: Addresses use CIDR notation.  To allow your 
 - Change 
ZEROCONF="false"toZEROCONF="true" - Change 
LISTENER="127.0.0.1"toLISTENER=""in order to listen for incoming connections all any network interface (not just thelocalhost/127.0.0.1). 
 - Change 
 - Edit 
/etc/init.d/distcc(e.g.sudo vi /etc/init.d/distcc)- Change 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bintoPATH=/home/YOUR_USER_NAME_HERE/x-tools/arm-unknown-linux-gnueabi/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin- Note: By following the "masquerade step" above, and placing the cross-compiler path BEFORE the standard search path, 
distccwill default to outarmgcc, as opposed to the normalx86/64gcc. - Note: YOUR_USER_NAME_HERE should be your username.
 
 - Note: By following the "masquerade step" above, and placing the cross-compiler path BEFORE the standard search path, 
 
 - Change 
 
 - Start 
distccon your Ubuntu machine- 
sudo /etc/init.d/distcc start(you may have to reboot if fails) 
 - 
 
 - Install dependencies
 - 
On the Raspberry Pi
- 
Install Avahi (Bonjour/Zeroconf)sudo apt-get install avahi-daemon avahi-utils
 - Install 
distccsudo apt-get install distcc
 - Configure the Raspberry Pi to use the Ubuntu helper you just configured
- Edit 
/etc/distcc/hosts(e.g.sudo vi /etc/distcc/hosts)- Remove 
+zeroconfand add a single-line space-delimited list of your helper machine IPs.- Note: Despite all of my best efforts, I cannot get RPI to recognize any distcc instances advertised over zeroconf, event when 
avahi-browse -acan see them. So, for the moment, helper distcc instances must be addressed via ip. 
 - Note: Despite all of my best efforts, I cannot get RPI to recognize any distcc instances advertised over zeroconf, event when 
 
 - Remove 
 
 - Edit 
 - To compile (finally!)
- First, figure out how many processors you have available on the Ubuntu Helper machine(s) using 
nprocon each. Tally the total number of helper processors. When we issue our make command we will use the-jflag to tell make how many jobs we want to be distribted over distcc. According to the distcc documentation, you should run make with 2 x TOTAL_PROCESSORS in your cluster. So, if you have one helper machine with 8 cores8x2=16, so you'll runmake -j 16. - Next, we need our makefiles to know that we won't be using the normal RPI gcc, but rather the gcc (etc) located in 
/usr/lib/distcc. The command itself looks like/usr/lib/distcc/g++or simplydistcc g++, rather than the normalg++. So the full make for the core openFrameworks lib OR projects will look something like this:make -j 16 CXX=/usr/lib/distcc/g++
 
 - First, figure out how many processors you have available on the Ubuntu Helper machine(s) using 
 
 - 
 
Note: This is particularly frustrating and does not work so far. Ideally one can follow the above steps with several additions / replacements.
- Install requirements
brew install gnu-sed gnu-awk coreutils binutils libtool intltool gettext- _Note: the 
gettextis keg only and requires LDFLAGS and CFLAGS 
 - Once the dependencies are installed, the above instructions should be ammended at the point of configuration to this:
./configure --with-install=/usr/local/bin/ginstall --with-sed=/usr/local/bin/gsed --with-objcopy=/usr/local/bin/gobjcopy --with-objdump=/usr/local/bin/gobjdump --with-readelf=/usr/local/bin/greadelf --with-awk=/usr/local/bin/gawk --with-libtool=/usr/local/bin/glibtool --with-libtoolize=/usr/local/bin/glibtoolize LDFLAGS=-L/usr/local/opt/gettext/lib CPPFLAGS=-I/usr/local/opt/gettext/include CC=/usr/bin/gcc --prefix=$HOME/x-tools/crosstool-ng- Note: This fails with errors.
 
 
- Nothing yet ...