Building a compiler with Crosstool-ng

What is crosstool-ng : http://www.crosstool-ng.org/

Step 1 – Preparation

Download and compile it :

$  git clone git://crosstool-ng.org/crosstool-ng
$  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

Usage

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

Sources

https://briolidz.wordpress.com/2012/02/07/building-embedded-arm-systems-with-crosstool-ng/

Laisser un commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s