This page tells you which tools to use and what to type for various cross-building tasks in Debian or Ubuntu. And also when not to crosscompile

Should I be cross-compiling?

Debian and derivatives are designed to be native-built. You are generally much better off building natively using all the standard tools unless you have a good reason to cross-build.

Situations where cross-building makes sense are:

  • You don't have access to suitable arm hardware (local or remote), or it simply doesn't exist yet
  • There is no suitable cross-build service (such as OBS) available to you
  • You need to build something repeatedly during development, it's a lot faster cross-building and you can fix any build issues
  • You need to target a flavour not supported by the standard armel,armhf or arm64 environments

How to cross-compile

If you need background information on how and why this stuff works read Cross Building

In general crossbuilding Debian packages will only be successful if the package supports cross-building. Many do, more don't. An online service is now available (Q1 2012) showing whether a package is knownn to currently cross-build in a particular distro or not.

Installing a toolchain

You need to install a cross-compiler

On Ubuntu raring (armhf supported)

apt-get install crossbuild-essential-armhf

On Ubuntu onieric (armel and armhf targets supported):

apt-get install g++-arm-linux-gnueabi arm-linux-gnueabi-pkgconfig

On Ubuntu onieric/precise/quantal (armel and armhf targets supported):

apt-get install g++-arm-linux-gnueabi

On Ubuntu natty (only armel targets supported):

apt-get install g++-4.5-arm-linux-gnueabi libc6-dev-armel-cross

On Ubuntu maverick (only armel targets supported):

apt-get install g++-4.4-arm-linux-gnueabi libc6-dev-armel-cross

On Debian (or Ubuntu if you want any arch other than armel) Add emdebian repository to apt sources:

deb http://www.emdebian.org/debian/ stable main

apt-get install g++-4.3-arm-linux-gnueabi linux-libc-dev-armel-cross

( armel, mips, mipsel, powerpc, sparc, s390, m68k, hppa, alpha, ia64, i386 and amd64 are all available)

For newer toolchains try newer repositories (but breakage due to version skew is common): deb http://www.emdebian.org/debian/ testing main

apt-get install armel-cross-compiler

To get a multiarch-ready toolchain use this repository: (armel and armhf targets currently supported) deb http://emdebian.org/~thibg/repo/ unstable main cross-deps

apt-get install c++compiler-arm-linux-gnueabi

Various cross-compiling scenarios

Pick whatever sounds most like your circumstances

You have the package source. All the dependencies are already present

Prerequisites: A cross compiler, build-essential, the package's cross-build-dependencies and build-dependencies

cd <package-version>
DEB_BUILD_OPTIONS=nocheck dpkg-buildpackage -a<arch>

e.g. cd

All the normal dpkg-buildpackage options are available and everything works just the same as a native build.

If the package uses pkg-config then you should ensure that pkg-config-arm-linux-gnueabihf is installed


You want to cross build a particular package from the archive, against the archive, using multiarch

Prerequisites: None, but the cross-build dependencies must have the right 'multiarch markup'

sbuild --host=<arch> package.dsc

This will download the package, use apt-get -a <arch> build-dep to install build-dependencies, and do the build.

You want to cross build a particular package from the archive, against the archive, using the older dpkg-cross method

xdeb --architecture <arch> --apt-source --prefer-apt --only-explicit <sourcepackagename>

e.g. xdeb --architecture armel --apt-source --prefer-apt --only-explicit acl

This will download the specified source package, download, cross and install its dependencies (including cross-dependencies), then cross-build the package.

It will leave -cross packages in your system, which after a while may start to cause trouble (when updates arrive upstream but your -cross versions are still the old ones - so fine in a stable environment, but not if you are trying to keep up with current releases of dependencies. It's best used inside a suitable chroot.

Note that the sources come from where apt thinks they should come from. The cross-dependencies are installed from a place configured in xdeb - so it's up to you to mnake sure they match if that's what you want.


You just want to install the cross-build-dependencies of a package in the archive

Prequisites: none

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

This will install the build-dependencies and cross build-dependencies for the specified architecture. It relies on packages having correct 'Multi-Arch:' headers (same, foreign, allowed) which is only true for things low in the dependency tree in summer 2012 and anything that doesn't need perl or python. It is rapidly becoming more effective over time.

If it doesn't work for your package you can manually install cross-dependencies using

apt-get install libfoo-dev:armel

There are less likely to be clashes if you do this in a chroot with less stuff installed than on your main system.

If you still can't get the build-dependencies you need then you need to fall back to the 'dpkg-cross' non-multiarch method:

xapt -a <arch> <package>

e.g. xapt -a armel acl

This will install all the build-deps and all the build-deps in -cross form (processed with dpkg-cross). It makes no attempt to work out whcih are native and which are cross deps and just does all of both. This can be a lot of packages, many of the -cross ones being empty.

This should only be used in a chroot to avoid getting too many -cross packages installed on your real system


You have no clue about this and just want to cross build a package

You have two options. 'New-style' and 'Old style'. Old style is still a bit more likely to work (summer 2012) but this will change over time.

  • New-style (Multiarch)

Prerequisites: None

sbuild --host=<arch> -d <distro> <package>

e.g.

sbuild --host=armel -d precise acl

This gets the dependencies and cross build-dependencies using apt, installs everything, then does the build.

  • Old-style (Dpkg-cross)

Prerequisites: Cross-compiler, build-essential

xdeb -a armel --apt-source <package>

That gets the sources from the repository, installs (cross)-build-dependencies and builds it. It will also try to do that recursively for any dependencies that are not available.

Note that the sources come from where apt thinks they should come from. The cross-dependencies are installed from a place configured in xdeb - so it's up to you to mnake sure they match if that's what you want. From v 0.6.5 (in Oneiric and Wheezy) you can choose to use an apt source or an xdeb-configured source for cross-binaries.


You have a set of local sources you want to build

xdeb -a armel <package>

That uses local sources rather than a repository.


You want to build a set of packages - e.g a mini-distribution like linaro-nano

Setting up a cross environment and cross-building all the packages in linaro-nano image is described here


CategoryCrossCompile

Platform/DevPlatform/CrossCompile/CrossbuildingQuickStart (last modified 2013-05-17 17:07:20)