I stumbled upon a great howto on building GCC cross compilers by Jeff Preshing and used his script to build a cross-compiler to compile Raspberry Pi programs on my Linux x86 desktop. In this post I explain how I did it and show how it’s like to compile programs with this cross-compiler.

## Gather Information From the Raspberry Pi System

I run uname -a on my Raspberry Pi system to find out the kernel version, which for me is 3.12.23.

## Configuring the Build

The cross compiler is built on the Linux system on which we want to compile our Raspberry Pi programs.

Open the script and change some variables according to the information gathered from the Raspberry Pi system.

A added --disable-werror to the CONFIGURATION_OPTIONS variable to disable the -Werror flag for binutils compilation. -Werror causes warnings to become errors and binutils was too optimistic to have this enabled for us.

## Run and Wait

Install the prerequisites, execute the build_cross_gcc script, and cross your fingers.

The script is easy to understand and self documented. If it fails you will see which command caused the failure and you will be able to find the command inside the script to understand which build step is problematic.

You can comment the first lines of the script to avoid running them again when you call build_cross_gcc for the thousandth time.

## Testing the Cross-Compiler

All the tools we need to compile Raspberry Pi programs are in the /opt/cross/bin directory.

Compile the following C program using our new cross-compiler:

You can check it’s actually an ARM program:

Send the program to your Raspberry Pi using SSH:

Now we can check if it runs properly on the Raspberry Pi:

This is success! Happy cross-compiling.