Get the Platform

The first thing we need to start off on our path, is to get the cross compile tools and platform on our computer. Sometimes external tools like crosstool-ng will help you build your own kit, and there are some excellent guides already on the Internet if you’re curious about that method. For simplicity, we’re lucky that the official RaspberryPi foundation has already provided the tools for us online.

(optional) Create a directory to store everything. I’ll be using ~/Development in my Ubuntu VM. Pull the RaspberryPi toolchain from https://github.com/raspberrypi/tools Check you have the directory raspberrypi-tool ( or just tools ) fully downloaded.

That’s it! You will be using the tools in this directory to build your RaspberryPi applications. This folder contains not just the “building” tools, but also all the standard libraries and system calls that could be needed by your application — we will be using several parts of this directory later.

Get the libraries

Most non-trivial programs you will build may require standard libraries, or external libraries not yet present on your system to be linked to. In most cases, simply downloading the relevant libraries and placing them in a lib directory was all that was needed. However, this is a bit more complicated for cross-compiling since you can’t reference an Intel compiled library for an ARM binary. There are ways to copy your library files directly onto your main development machine and reference them that way — however, that means you are still dependant on compiling something on your Pi.

For this example I’m going to be using the standard pthreads library, a locally-compiled open-source wiringPi library, and the current C11 standard with our compiler. These should give you a good example base to start adding more libraries and options if you need them.

The pthreads library is standard, and already included in our already-downloaded toolchain, so we don’t need to worry about that for right now. Our last step here is to simply pull the current wiringPi repository from http://wiringpi.com/download-and-install/.

Get the test code

Right now, we’re just focused on getting the compiler and build system working — so let’s not worry about compiling anything too complex. The “blink” example from the wiringPi website should fill our needs nicely: