There is a lot of information on the internet that explains how to cross compile software for the Raspberry Pi. But this information is scattered into tiny pieces and a lot of advice is just wrong or cumbersome.
In this blog post I will explain how to cross compile most autotools projects.
At first we need to get a cross compile toolchain and a sysroot environment for the Raspberry Pi. Luckily the Raspberry Pi Foundation does provide both on their github profile. So we’ll can just clone them to our computer.
Note that I used the attribute
--depth 1 which tells git only to fetch data from the latest commit. As the tools repository is rather large this minimizes the amount of data we have to download.
We will use the
arm-linux-gnueabihf cross compiler which is at the time of this the latest and seems to support all Raspberry Pi devices. The next step is to get a hold of tools the toolchain provides.
There are more but for most projects those are sufficient. Further we need the sysroot environment for this toolchain and add it to our compiler flags.
Any autotools project is configured with a configure script. Thus we need to provide the configure script with the tools and flags we prepared.
To get the cross compiled resources we need to install them to a location of our choosing.
A lot of project use pkgconf to find dependencies. Therefore we tell autotools where to find Raspberry Pi specific pkgconf configuartions.
We might have to cross compile dependencies ourselves. That’s why we let pkgconf look into our install directory for dependencies as well.
Finally we can start building our project. In this example I will compile ZeroMQ’s
libzmq and higher level binding
czmq to demonstrate that self compiled dependencies are detected as well. If you’ve used autotools before you should be familar with the build steps. Only difference are the
CONFIG_OPTS we supply.