Cross-compile Bitcoin for ARM

2016-02-23
•
bitcoinARMg++crosstool-ng

Introduction

So you want to cross-compile Bitcoin (or any C/C++ program in fact) from your x86_64 host machine for an ARM “target” machine.

This little howto aims to help you with that.
It’s intended for intermediate level, i.e. you should be familiar with the ./configure and make commands but you don’t need to have earlier experience with cross-compilation.

The first step is to identify what’s called the target triplet.
An easy way to do so is to run gcc -dumpmachine on the target machine.
If you don’t have gcc installed, you can install it to run that command then uninstall it right away.

In my case, I have:

$ gcc -dumpmachine
arm-linux-gnueabihf

You’ll have to replace arm-linux-gnueabihf with whatever you get for the rest of this howto.

Install a cross-compiler for our target platform

If you’re running Arch Linux, there might be an AUR package for you.
If you’re not running Arch or you want to use a more generic method, you can skip to the next paragraph which explains how to use crosstool-ng.

On any distro using crosstool-ng

First, you need to install crosstool-ng, the executable is named ct-ng and should be available to a non-root user.

Then we check if ct-ng knows our target architecture:

$ ct-ng list-samples | grep arm-linux-gnueabihf

If you can’t find an exact match, just run ct-ng list-samples and pick the closest one, like arm-unknown-linux-gnueabi or maybe armv7-rpi2-linux-gnueabihf.
To select it, simply run:

$ ct-ng arm-unknown-linux-gnueabi

Now we need to build the actual toolchain.
This will take a long while as it downloads a copy of the Linux kernel, binutils, gcc, etc. then builds gcc itself, etc.
That will require a few gigs of disk space and burn your CPU for a while…

If you’re in a rush, you can skip building some of the tools such as gdb, etc.
You can do that with ct-ng menuconfig then unselect what you don’t need.

$ ct-ng build

When it’s finally done, you should have a new directory named ~/x-tools/:

Compiling Bitcoin

We’re on the home stretch!
Getting a cross-compiler to work was probably harder than compiling Bitcoin itself.
Let’s start by fetching the source code and checking out the latest tagged release (v0.12.0 at the time of this writing):