Building Cross Compiler for Raspberry Pi using Crosstool-NG

Home / Building Cross Compiler for Raspberry Pi using Crosstool-NG

A cross compiler is a compiler that runs on one platform/architecture but generates binaries for another platform/architecture. 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 way to go.

While there are a lot of different methods for building cross-compilers, by far the quickest and easiest is to use crosstool-ng. This is a set of scripts that bring up a menuconfig-like interface to choose your compiler settings, then goes off and downloads what it needs, patches it, configures it, builds it and installs it all for you.

For this article I use:

  1. Slackware64 14.0 (Linux)
  2. crosstool-ng

Crosstool-NG Overview

Crosstool-ng is a set of scripts that bring up a menuconfig-like interface to choose compiler settings. The project aims to build a toolchain. Crosstool-ng also support alternative components such as uClibc, glibc, or eglibc.


Our example will build a cross compiler toolchain for Raspberry Pi, which use ARMv6 and running Linux as operating system. This will assume our OS on Pi only Linux and we cannot use this toolchain to build for other OS (RISC OS, etc).

Obtain Material

Download crosstool-ng from their official site. The latest version available per August 30th 2013 is crosstool-ng 1.18. Once the download complete, extract the content.

We also need to install crosstool-ng to our system. Let’s say we want to install it to /opt/crosstool-ng

To complete above, do following:

tar xjf crosstool-ng-1.18.0.tar.bz2
cd crosstool-ng-1.18.0
./configure --prefix=/opt/crosstool-ng
make install
export PATH="${PATH}:/opt/crosstool-ng/bin"

For installation of crosstool-ng, make sure you do `make install` using root privileges.

Preparing Environment

We need a working directory for compiling our cross-compiler. This will contain toolchain configuration, downloaded files, and intermediary build results. This is not where the final location the toolchain will end up. You should reserve some space, at least 3.5GB.

Create a directory, you choose it. For example, I will use ~/working as the working directory. Go to that directory.

mkdir ~/working
cd ~/working

Compilation & Installation

Go to working directory.

Run ct-ng script to display you a configuration menu. Make sure /opt/crosstool-ng/bin is in your search path.

ct-ng menuconfig

You should see some configuration options there.

Here is the important stuff:

Path and misc options

  • Enable “Try features marked as EXPERIMENTAL”.
  • Change the prefix directory, from ${HOME}/x-tools/${CT_TARGET} to /opt/cross/x-tools/${CT_TARGET}

Target options

  • Change the “Target Architecture” to arm
  • Change the “Endiannes” to Little endian
  • Change the “Bitness” to 32-bit

Operating System

  • Change “Target OS” to Linux

Binary utilities

  • Change “binutils version” to the latest one you can find which isn’t marked as experimental (at this time 2.22)

C Compiler

  • Enable “Show Linaro versions”
  • In the gcc version field, choose the Linaro version of gcc

Once the configuration done, save it.

To build the toolchain, do following:

ct-ng build

This should take some times, minutes in my case.

Once it done, you should have cross toolchain reside on /opt/cross/x-tools/arm-unknown-linux-gnueabi/bin. You might want to add this to your search path.


First, test the version

arm-unknown-linux-gnueabi-gcc --version

Now test for the compilation. Write this source code as test.c.

#include <stdio.h>

int main() {
    printf("Hello, world!\n");
    return 0;

and compile it.

arm-unknown-linux-gnueabi-gcc -o test test.c

, , ,

About Author

about author


A man who is obsessed to low level technology.

1 Comment
  1. Installing ARM Development Studio 5 - Community Edition - Xathrya.ID

    […] you don’t want create a cross compile toolchain by yourselves, this method is suitable for […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Social Share Buttons and Icons powered by Ultimatelysocial