Building a compiler with Crosstool-ng

What is crosstool-ng :

Step 1 – Preparation

Download and compile it :

$  git clone git://
$  cd crosstool-ng
$  ./configure --enable-local 
$  make

Step 2 – Configuration

Configure your target (ex: arm architecture) :

$ ./ct-ng arm-unknown-linux-gnueabi

If you are not sure about the target you need, you can check the existing ones :

$ ./ct-ng list-samples
[L..] armeb-unknown-linux-gnueabi
[L..] x86_64-unknown-linux-gnu
[L..] x86_64-unknown-linux-uclibc
[L.X] x86_64-w64-mingw32
[L..] xtensa-unknown-linux-uclibc
 L (Local) : sample was found in current directory
 G (Global) : sample was installed with crosstool-NG
 X (EXPERIMENTAL): sample may use EXPERIMENTAL features
 B (BROKEN) : sample is currently broken

Step 3 – Generation

Generate the compiler :

$ ./ct-ng build


Once the compilation is done,

$ export PATH=crosstool-ng/.build/arm-unknown-linux-gnueabi/buildtools/bin/:$PATH
$ export CCPREFIX := arm-unknown-linux-gnueabi-
$ export AS := $(CCPREFIX)as
$ export LD := $(CCPREFIX)ld
$ export CC := $(CCPREFIX)gcc
$ export AR := $(CCPREFIX)ar

You can also repeat the build operation on different target to generate all you need:

$ ./ct-ng arm-unknown-linux-gnueabi 
$ ./ct-ng build
$ export PATH=crosstool-ng/.build/arm-unknown-linux-gnueabi/buildtools/bin/:$PATH

Possible errors

[ERROR] g++-4.6.real: internal compiler error: Killed (program cc1plus)

This happended to me on a board with not enough memory. You can temporarily add more swap :

dd if=/dev/zero of=swap.img bs=1024k count=1000
mkswap swap.img
swapon swap.img