Original address: http://www.bootc.net/archives/2012/05/26/how-to-build-a-cross-compiler-for-your-raspberry-pi/
A cross compiler are a compiler that runs on one platform/architecture but generates binaries for another Platform/architec Ture. With devices like the Raspberry Pi, where you really don't have much CPU or memory to work with, if you ' re doing any heavy Compiling (like when working on the kernel) a cross compiler is the only-to go. For example, I-Build all my Raspberry Pi kernels on my nice Sandy Bridge Xeon E3 Home Server where they compile in only a Fraction of the time they would on the Pi.
While there was a lot of different methods for building cross-compilers, by far the quickest and easiest was to use Crossto Ol-ng. This was a set of scripts that bring up a menuconfig-like interface to choose your compiler settings, then goes off and Dow Nloads What it needs, patches it, configures it, builds it and installs it all for you. Here's how to get started:
- Download Crosstool-ng from the Project Web site. I ' ve used version 1.15.2 as that is the latest when I wrote this.
- Unpack
cd
the tarball and into the unpacked directory, then run ./configure --prefix=/opt/cross
. You can pick somewhere else instead of the /opt/cross
where I like to keep it.
- Run
make
and sudo make install
.
- Make sure are in
/opt/cross/bin
your $PATH
.
Right, so the ' s crosstool-ng installed and ready to build a toolchain for you. Next, to actually create your Raspberry Pi toolchain:
- Create a directory somewhere in your home directory that crosstool-ng would use as a staging ground. This would contain your toolchain configuration, downloaded files, and intermediary build results. This is not where your final toolchain would end up, and does take up quite a lot of space (3.5GB and up for me). into
cd
your chosen directory.
- Run
ct-ng menuconfig
. You should see the Ct-ng configuration menu.
- Go into Paths and misc options. Enable Try features marked as experimental. This is important.
- While you ' re there the want to change your Prefix directory. I like to put all my toolchains in
/opt/cross/x-tools/${CT_TARGET}
instead of ${HOME}/x-tools/${CT_TARGET}
.
- Go back to the main menu and select Target options.
- Change of the Target architecture to arm. Leave Endianness set to Little endian and bitness set to 32-bit.
- Go back to the main menu and select Operating system (Skip toolchain options, the defaults is fine) .
- Change Target OS to Linux.
- Go back to the main menu and select Binary utilities.
- Change binutils version to 2.21.1a or whichever are the latest that isn ' t marked as experimental. Probably unnecessary but I prefer this.
- Go back to the main menu and select C compiler.
- Enable the Show Linaro versions (experimental) option.
- In the GCC version field, choose the linaro-4.6-2012.04 (experimental) compiler. You ' re free to choose a different one but I know the one works well. I do recommend the Linaro versions over the vanilla ones for the RPi.
- All the other settings is fine left at their default values. Exit the Configuration tool and save your changes.
- Run
ct-ng build
.
- Go away and make a coffee, etc ... This bit would take some time.
- You should end to with a freshly baked arm compiler ready for building kernels (and other things) for your Raspberry Pi in Your Prefix directory you chose above.
- Just add your compiler directory to your and
$PATH
start compiling. If you used my preferred prefix directory, you would want to add /opt/cross/x-tools/arm-unknown-linux-gnueabi/bin
.
Compiling cross-compilation environments with Crosstool-ng automation (RPM)