RPi Linaro GCC Compilation
Back to the Hub.
Software & Distributions:
Software - an overview.
Distributions - operating systems and development environments for the Raspberry Pi.
Kernel Compilation - advice on compiling a kernel.
Performance - measures of the Raspberry Pi's performance.
Programming - programming languages that might be used on the Raspberry Pi.
This page explains how to build yourself a version of Linaro GCC specifically for building software for the RPi.
From the Linaro website: "Linaro GCC is performance focused branch of the current GCC stable release and includes backports of the improvements and bug fixes that Linaro and others have done upstream" 
This process should be carried out on the Linux system you wish to compile RPi software on. Therefore, you will require a reasonably powerful computer (preferably 64bit). If you are running on Windows, it is possible to use a linux virtual machine running on Virtualbox. The only software required is crosstool-NG (plus its dependencies).
The whole process takes about an hour on a dual-core 2.8GHz 64-bit AMD system using an 8Mbit ADSL connection. NOTE: This procedure was tested on 24th November 2012 using crosstool-ng 1.17.0. It may not be accurate for newer versions of the software.
- Download the crosstool-NG source (from http://crosstool-ng.org/).
- Extract the source tarball into your home directory:
tar -xjvf crosstool-ng-1.17.0.tar.bz2
- Or clone a more recent version from git, I saw this newest version work as well:
git clone https://github.com/crosstool-ng/crosstool-ng.git cd crosstool-ng git checkout 1.22
- Change to the extracted directory, then configure it. You should specify an installation prefix to keep it separate from the OS in case you want to run multiple versions - we are using /opt/crosstool-ng-1.17.0 in this example:
- If configure fails due to missing dependencies, install them for your platform using the package manager (i.e. yum install, apt-get install, etc.)
- during the build you might need packages for expat, libexpat1-dev, python-dev
- When configure completes successfully, make and install it:
make make install
- Add the crosstool-NG bin folder to your path. The easiest way to do this is add it to PATH in your .profile, for example:
Build GCC Linaro
- Make a new directory in your home directory where you want to run crosstool-NG, then change to it.
- Configure crosstool-NG:
- Set the following options (derived from the arm-bcm2708hardfp-linux-gnueabi build on GitHub):
- Paths & Misc:
- Check "Try features marked as EXPERIMENTAL"
- Set "Prefix directory" to whereever you want the finished toolchain to be placed (e.g. /home/<yourname>/crosscompile)
- Set "Number of parallel jobs" to be the number of processor cores in your system x1.5
- Target options:
- Set "Target architecture" to "ARM"
- Set "Endianness" to "Little endian"
- Set "Bitness" to "32-bit"
- Set "Architecture level" to "armv6zk"
- Set "Emit assembly for CPU" to "arm1176jzf-s"
- Set "Tune for CPU" to "arm1176jzf-s"
- Set "Use specific FPU" to "vfp"
- Set "Floating point" to "hardware (FPU)"
- Set "Default instruction set mode" to "arm"
- Check "Use EABI"
- General toolchain:
- Set "Tuple's vendor string" to "rpi" - you can choose whatever you like here and it will appear in the compiler filenames.
- Operating system:
- Set "Target OS" to "linux"
- Set "Linux kernel version" to match that running on the RPI (it was tested with the 3.6 branch patched to version 3.6.3)
- Binary utilities:
- Set "Binary format" to "ELF"
- Set "binutils version" to "2.22"
- C compiler:
- Check "Show linaro versions"
- Set "gcc version" to "linaro-4.7-2012.10"
- Check "C++"
- Set "gcc extra config" to "--with-float=hard" (Note: see "Discussion" page)
- Check "Link libstdc++ statically into gcc binary"
- Set "C library" to "eglibc", or, as eglibc gets deprecated, glibc from version 2.19 up.
- Set "eglibc version" to "2_13", however, to reduce the size of your executables you could also try to match it with the libc already present on the Pi and select a custom libc-version here, for example the exact commit your libc was build from if you can reveal that. The major version of libc can be made visible with
- Paths & Misc:
- Build it:
- All the required source will now be downloaded and built - exact times vary according to processing power and internet connection speed.
Configure system to use new compiler
Your compiler will be located in /home/<yourname>/crosscompile (or whereever you specified in the configuration). You can choose to move it to another location (e.g. /opt/arm) if you want to. Then, add that location to your PATH:
Now if you run:
you should get the version information from your new build. It should end something like:
gcc version 4.7.3 20121001 (prerelease) (crosstool-NG 1.17.0)
By the way, this manual also works for the newest stable gcc-linaro-5.3-2016.05 at http://releases.linaro.org/components/toolchain/gcc-linaro/5.3-2016.05/