view · edit · print · history

Cross-Compiling from Debian on a PC to OpenDebianSlug

This page describes two ways to set up a cross-compilation environment for OpenDebianSlug on a Debian PC. You can either install binary packages, or do it yourself.

Installing from binary packages

Pre-built cross-compiler packages resulting from the steps described in the rest of this page be found at http://ftp.armeb.net/other/sarge.cross-toolchain/. <<--this is broken

In that directory you'll find a set of .deb files. You'll also find a .tar.gz file containing all of the compiler and library files. This is not a .deb file so the Debian package system won't know anything about it, and it may be possible to use it on other systems.

(Note: I don't think that these packages include the gcc-3.3 patch mentioned below, so they won't work with the current version of dpkg-cross.)

Doing It Yourself

There are three main steps:

  • Install the OpenDebianSlug libraries on the PC.
  • Build binutils (assembler, linker etc).
  • Build compilers (gcc and g++).

These steps are described in the rest of this page.

Things are easier now that big-endian ARM has some Debian support; if you're using an old Debian system you may need to hack things a bit. Look at the history of this page for the now-deleted details.

Installing the OpenDebianSlug libraries

You need the OpenDebianSlug libraries and include files on the PC so that your programs can be linked with them. You need to install a few basic libraries before starting work on binutils and gcc because they make use of them during installation. You can add other libraries, as needed by your programs, later in the same way.

You cannot just install the OpenDebianSlug .debs on your PC for two reasons. First, the Debian installation tools will refuse to install them because they are for the wrong architecture. Second, you don't want to replace your native PC libraries with ARM code; these libraries must be installed in a special location. Both of these issues can be fixed by using the dpkg-cross tool to convert the .debs. So install dpkg-cross, if you don't already have it. You probably also need fakeroot:

# apt-get install dpkg-cross fakeroot

(You need a version of dpkg-cross >= 1.26 for big-endian ARM support.)

You should review /etc/dpkg-cross/cross-compile, though its default settings are fine. Your armeb-specific files will be installed under /usr/armeb-linux-gnu/.

Now get the OpenDebianSlug .debs for at least the following libraries:

  • libc6 (in /debian/pool/main/g/glibc/)
  • libc6-dev (in /debian/pool/main/g/glibc/)
  • libdb1-compat (in /debian/pool/main/d/db1-compat/)
  • linux-kernel-headers (in /debian/pool/main/l/linux-kernel-headers/)

It's probably easiest to wget them from http://armeb.debian.net/debian-armeb/debian/sarge/pool/main/ . These files will have names ending _armeb.deb, indicating that they are for the armeb architecture. If you try to install them on your PC you'll get an error message.

Convert them using dpkg-cross as follows:

$ dpkg-cross -b -a armeb *_armeb.deb

This will generate a new .deb for each package. The new filename will end _all.deb indicating that it can be installed on any machine, and will contain armeb-cross within the name indicating that it is for armeb cross-compilation. You can now install these files:

# dpkg -i *_all.deb

Building binutils

Version 2.17 of binutils should build without patching. For older versions, see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=231707 and the history of this page.

The build procedure is as follows:

$ apt-src install binutils

(You should be able to run apt-src is a normal user, but running as root means that it will be able to install the native tools necessary for building binutils automatically. You'll then need to chown it all so that you can build as a normal user.)

$ cd binutils-*
You might want to review debian/README.cross at this pont.

Now build the tools:

$ TARGET=armeb-linux-gnu fakeroot debian/rules binary-cross

(Note that it's now armeb-linux-gnu, not just armeb-linux.)

This will create a .deb, which you need to install:

$ cd ..
# dpkg -i binutils-armeb-linux-gnu-2.*.deb

Building gcc

Before you start working on gcc, check that you don't have a buggy version of awk. See http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=303263. Try this:

$ fakeroot awk '' </dev/null

It should do nothing. If you see an error message you need to upgrade from 1:3.1.4-2 (=sarge) to 1:3.1.4-2.0.1 (>=etch).

The Debian gcc package has support for building cross-compilers built in, now including the necessary patches for big-endian ARM, even in the gcc-3.3 packages. If you're targetting a stable OpenDebianSlug NSLU2 you'll want gcc-3.3; if your target is more up-to-date you can use a newer version of gcc. This page assumes gcc-3.3.

$ apt-src install gcc-3.3
(As with binutils, doing this as root will install the build deps.)

$ cd gcc-3.3-3.3.*
At this point, at the time of writing you need to apply a patch to make gcc-3.3 compatible with dpkg-cross. This patch may be included in a future version; check the changelog. Equivalent patches have already been included in gcc-3.4, 4.0 and 4.1. Get the patch from http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=357629, saving it as 357629.patch.

Unfortunately this patch isn't quite right, at the time of writing (Aug 28 2006). You need to replace references to GCC_SO with CXX_SO in places where libstdc++ is mentioned.


$ patch -p1 < 357629.patch

You might like to review debian/README.cross at this point.

Now you can compile:

$ export GCC_TARGET=armeb
$ ./debian/rules control
$ dpkg-buildpackage -rfakeroot

This will create several .debs including gcc and g++ and their run-time libraries.

Note that the resulting .debs depend on gcc-3.3-base, which is shared with your native compiler, and must be the same version. You may need to install or upgrade it.

You can now install your new cross-compiler:

# dpkg -i *.deb


You can test the tools as follows:

$ armeb-linux-gnu-gcc -o hw hello.c
$ file hw
hw: ELF 32-bit MSB executable, ARM, version 1 (ARM),
for GNU/Linux 2.2.0, dynamically linked (uses shared libs), not stripped

Copy the executable to your slug and see if it works!

view · edit · print · history · Last edited by Ropetin.
Based on work by SyNko, Phil Endecott, dyoung, martin w, marcusb, hs, rwhitby, buytenh, and Leak.
Originally by Phil Endecott.
Page last modified on September 26, 2008, at 10:00 PM