Hi, It's been three weeks already since the end of the Google Summer of Code 2012, and I've been told I still haven't blogged about the state of multiarch cross-toolchains. So, here it is!
Building multiarch cross-toolchains
This section is mostly a rehash of my previous post. Cross-toolchains build properly for most architectures in Debian, with the exception of arches having clashing ld.so paths. The following instructions assume you are using Wheezy or unstable, and have applied my patches.
Adding a foreign architecture
You are going to use some packages meant for a different architecture than your native one. This means you'll have to tell dpkg about a foreign architecture, for instance, armel.
# dpkg --add-architecture armel
Then, you need to update apt's database.
# apt-get update
If one of the repository you use only supports a subset of your configured architecture (for instance, when working with an unofficial port), you will need to use arch restrictions in your sources.list (see the manpage).
Absolutely nothing has changed there, it works exactly the same way it did before the GSoC. That is, grab binutils' source package, set $TARGET to a GNU triplet or a Debian arch, and run dpkg-buildpackage.
$ apt-get source binutils $ cd binutils-*/ $ TARGET=arm-linux-gnueabihf dpkg-buildpackage -uc -us -b
Building cross-gcc is done the same way it was before the GSoC, except it uses cross-arch dependencies instead of mangled packages for foreign packages. This means you shouldn't use dpkg-cross at all, but use multiarch instead.
If you haven't done so yet, apply my patches.
Then, building the cross-compiler is as easy as running (with $target being a Debian arch name):
$ export DEB_CROSS_NO_BIARCH=yes $ export GCC_TARGET=$target $ debian/rules control $ dpkg-buildpackage -uc -us -b
Biarch/multilib and multiarch do not really play well. Using some trickery, you might be able to build multilib cross-compilers, but I would recommend building two cross-compilers instead.
You will of course need to install the required build-dependencies, some of which are packages for the target architecture, but that is no different from building any other Debian package, provided that multiarch is correctly configured.
This will produce cross-compilers packages using multiarch paths and cross-arch deps, along with some binary packages for the target architecture. Those binary packages are cross-built versions of the runtime libs. They are not needed, as they should be identical to the natively-built ones present in the archive, but using them shouldn't be a problem.
Installing the cross-toolchains
Installing cross-binutils is straightforward, installing cross-gcc itself is, but installing cross-g++ is not. Indeed there is bug #678623: g++-4.7 depends on libstdc++6-4.7-dev, which is multiarch-unaware and depends on g++-4.7. Assuming you've compiled your cross-gcc using my patches, the cross-compiled libstdc++6-4.7-dev will not have these problems, but still won't be co-installable with your native libstdc++6-4.7-dev, since it's not M-A: same. The easiest way to work around this issue is probably to download the binary package, modify its control file to include “Multi-Arch: same”, and install the modified package.
Using the cross-toolchains
Once installed, using the cross-toolchains should be as easy as running “$triplet-gcc-4.7 file.c”. Note the “-4.7” part. Indeed, the cross-compilers packages do not provide the “$triplet-gcc” symlink. This matches what is done with the native compiler pase, where the “gcc” symlink is not provided by the compiler's package, but by the “gcc” package. However, there is no “cross-gcc” package or anything like that yet, which means you have to use the full name, or provide the symlink yourself.
Another issue is pkg-config. To know where to search for libraries, pkg-config has to be told which architecture you are compiling for. Autotools does that by calling “$triplet-pkg-config” instead of “pkg-config” if it exists. The “pkg-config” binary packages comes with a wrapper you can symlink to: “/usr/share/pkg-config-crosswrapper”.
Despite a few shortcomings (bug #678623, missing symlinks, multilib issues and clashing ld.so paths), multiarch cross-toolchains are already usable on Wheezy. There is still quite a lot of work left (like fixing #678623, splitting gcc-4.7 in two, or changing wanna-build, britney etc. to handle cross-arch deps) but hopefully this will be done for Jessie.