CrossToolchains

This is in flux

This document describes cross-toolchains in Debian. Some of this is now in unstable, but only cross-binutils-* is in Jessie - other Jessie-compatible packages are available in the Debian Cross-toolchains repo. Some of this is still plans and packages in experimental, intended to be released in Stretch.


Talks:

Pages of largely historical interest:

Status of cross-toolchains in the Debian archive

In jessie/testing

In unstable

In experimental

Status of cross-toolchains in Ubuntu

Current details are given on https://wiki.ubuntu.com/ToolChain#Cross_development_toolchain

If you have an Ubuntu system, cross-toolchains (i386 & amd64->armel) have been included since 10.10/Maverick. From 12.10/Quantal onwards there are crossbuild-essential-<arch> convenience packages to install cross toolchains, cross-pkgconfig and (multiarch) cross-libc. Armel then armhf were initially supported. Arm64, powerpc and ppc64el were added later.

All these toolchains search multiarch library and header paths by default so are suitable for multiarch crossbuilding.

Installation

For jessie/testing

Cross-toolchains for jessie are available, but only cross-binutils is in the main archive. Other packages come from an external repository.

The toolchains install on amd64 and i386 machines, targeting the jessie release architectures:

Currently cpp, gcc, g++, and gfortran are built. It's easy to build more languages so ask if you have a need. gccgo and gobjc will be added soon.

These packages did not make it into Jessie so you need to install them from the Debian Cross-toolchains repository. Create /etc/apt/sources.list.d/crosstools.list containing:

deb http://emdebian.org/tools/debian/ jessie main

You will need the archive key installed.

curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | sudo apt-key add -

The key fingerprint is: 084C 6C6F 3915 9EDB 6796 9AA8 7DE0 8967 1804 772E (you will need to install curl in a bare chroot)

crossbuild-essential-<arch> packages exist to aid in installing the correct cross-packages. For instance to install the armhf cross-toolchain, first enable the foreign architecture (and update), then install crossbuild-essential-armhf :

sudo dpkg --add-architecture armhf
sudo apt-get update
sudo apt-get install crossbuild-essential-armhf

This will pull in the required packages to cross-build for the target architecture, namely libc6-dev:<arch>, gcc-<triplet>, g++-<triplet> and dpkg-cross.

For unstable

You must enable the appropriate (HOST) foreign architecture before installing the cross-compiler.

dpkg --add-architecture armhf
apt-get update

It is recommended to install the cross environment like this as that pulls in all the necessary components:

apt-get install crossbuild-essential-<arch>

i.e

apt-get install crossbuild-essential-armhf

But you can install just the compiler with

apt-get install gcc-arm-linux-gnueabihf

Note that gcc-arm-linux-gnueabihf is (like the native 'gcc') just a metapackage, which brings int he current version of the actual compiler gcc-4.9-arm-linux-gnueabihf (c.f. gcc-4.9)

g++-<triplet>, gfortran-<triplet>, gobjc-<triplet> and gccgo-<triplet> packages also exist.

Using a chroot of unstable

For any release older than Jessie, the simplest way is to create a chroot of unstable and install your toolchain & build the package there. This is particularly simple if you are simply building a kernel or a package with only libc build dependencies.

$ sudo debootstrap sid sid
$ sudo chroot sid
# dpkg --add-architecture armhf
# apt install gcc-arm-linux-gnueabihf

For Wheezy

Without a chroot, you are blocked. Emdebian.org did have 'unstable' packages which would work on wheezy but these need to be restored after a server compromise.

For Squeeze

Without a chroot, you are blocked. Emdebian.org had packages which worked nicely but these need to be restored after a server compromise.

Older

Emdebian.org keeps some 2.95 vintage packages in case that's useful (people do still ask occaisionally!). Currently awaiting re-uploading.

Future cross-toolchain implementation (currently experimental)

Debian provided basic cross-toolchain support in the archive from November 2014 onwards. Previously this had only been available from external repositories.

These are generally built to run on fast architectures (amd64, ppc64el, arm64), and target all reasonably popular architectures (arm64, armel, armhf, powerpc, ppc64, i386, amd64, mips, mipsel, mips64el).

They will be automatically installed (by the magic of multiarch) if you enable the architecture you are building for, and install build-essential for a target architecture, or a package which directly depends on gcc-for-host.

!Note the BUILD architecture is the machine you are building _on_. the HOST architecture is the one you are building _for_

Installation concepts for experimental

To cross-build (or install cross toolchains) you will need to enable multiarch for the architecture you are building for (the HOST arch) (unless targetting an architecture that is not in Debian, in which case the cross-toolchain will be installable without any foreign-arch packages).

dpkg --add-architecture armhf
apt-get update

Use the debian architecture name to install toolchains (or cross-toolchains)

apt-get install -a<arch> build-essential

i.e

apt-get install -aarmhf build-essential

Note that the toolchains thus installed must be used as <triplet>-gcc, for both native _and_ cross usage. i.e. x86_64-linux-gnu-gcc for the native compiler on amd64, and arm-linux-gnueabihf-gcc for the cross-compiler targetting armhf.

Plain 'gcc' will (probably) not be installed.

Which packages are what?

Packages which need a particular version of gcc should build-depend on gcc-4.9-for-host Packages which also need the build-arch gcc when cross-building, should build-depend on gcc-for-build (for the default version) or gcc-4.9-for-build (to get 4.9 specifically).

Similar packages exist for g++, cpp, gfortran, binutils and pkg-config.

Installing build-dependencies

apt-get build-dep -a <arch> <package>

e.g.

apt-get build-dep -a armhf util-linux

If the build-deps are not installable in this way (usually due to un-multiarched packages in the dependency tree), then use dpkg-checkbuilddeps and apt-get install to manually insert the right packages.

Information for package maintainers

In the pre-multiarch-crosscompiler world (jessie and earlier) a package could run 'gcc' and expect to get the compiler targetting the native arch and running on the native arch (e.g amd64,amd64). And it could build-depend on 'gcc-4.7' to get an older compiler installed. However There was no way to depend on a particular compiler version and have that version of the cross-compiler installed, so this scheme made any package needing a particular gcc version uncrossbuildable (without a lot of faffing).

In stretch build-essential implicitly depends on the compiler for the HOST architecture (which is the architecture you are building _for_) via 'gcc-for-host'. This is the default compiler, which must be run specifying the TARGET architecture (the one you want to build code for), i.e. as x86_64-linux-gnu-eabi-gcc. Don't call 'gcc' as it may not do the right thing, or work at all.

Packages that need a specific version of the compiler can now depend on 'gcc-<version>-for-host' and will get the <triplet>-gcc for the (HOST) architecture that the build is targetting.

See the multilib section for info on why it is recommended to always call the compiler as <triplet>-gcc

How does this _really_ work

Details of the gcc interface and metapackage design are in https://wiki.debian.org/Sprints/2014/BootstrapSprint/Results

Appropriate info needs extracting to here

Sources

In the archive things are arranged like this:

The missing sources (cross-gcc-bootstrap, gcc-cross-support, cross-support) repos will be uploaded there shortly so that everything is in one place for maintenance.