Friday 16 November 2012

Guide To Building a Raspberry Pi C/C++ compiler on Ubuntu


These are personal notes on setting up a Cross Compiler for C/C++ on my Ubuntu 12.04 machine, so I can build programs for the Raspberry Pi.

Of course my reason for this is that my PC's are far more powerful than my Pi, even compiling the most trivial program can result in waiting a duration or two on the Pi.  So, I want to employ my heavy PC metal to generate the ARM architecture code for me.

The first steps were to install all the pre-requisites, I'm assuming you have Ubuntu 12.04 32bit LTS installed fresh and clean (either as a real machine, or as a virtual one) and that you know how to use your Linux Machine, here we go.

sudo apt-get update
sudo apt-get upgrade
sudo shutdown -r now

Reboot... Log back in etc....

sudo apt-get install subversion bison flex gperf build-essential texinfo gawk libtool automake

Download ncurses tar ball from "http://ftp.gnu.org/pub/gnu/ncurses" extract it and then within its folder:

./configure
sudo make install

Download crosstool-ng from "http://www.crosstool-ng.org", extract its tar ball and from its folder:

./configure --prefix=/opt/cross
sudo make install

Now we need to add this built item to the path:

PATH=$PATH:/opt/cross

And now we need a space to do the building of the cross compiler:

cd ~
mkdir Pi
cd Pi
/opt/cross/bin/ct-ng menuconfig

Goto "Paths and misc options" and then turn ON "Try features marked as EXPERIMENTAL".

Goto "Target Options" and into "Target Archetecture" and select "ARM".
Go into "Target Options" and set Endieness to "little".
Go into "Bitness" and set it to "32bit".

Goto "Operation System"
Go into "Target OS" and select "Linux".

Goto "Binary Utilities" and then select "Binary Utilities" latest version (2.22 as of writing).

Goto "C Compiler" and enable "Show Lincro Version" these are the 4.7+ versions supporting C++11, and enable C++.

Exit and save.

And now we kick off the building of the tool chain:

/opt/cross/bin/ct-ng build

The output for me ended up in "~/x-tools/" as per the paths selected in the paths & misc options.

No comments:

Post a Comment