Gentoo Wiki


This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc

The Gentoo Documentation describes the cross development and how to do so over multiple PC's. This guide is a supplement to them.



From How can I build a cross compiler?: Now Ref. mingw hosted cross compiler
"Cross-compiling refers to building applications for one platform, with development occuring on another platfrom (i.e. compiling MS-Windows executables from within a Linux environment, or vice-versa)."


Cross compile to arm-something-linux-uclibc

First emerge crossdev:

Before generating anything you will need to add the PORTDIR_OVERLAY variable (the directory in which user made ebuilds may be stored and not overwriten when `emerge --sync` is run.) in /etc/make.conf like this:


Second step is to generate the cross environment with the following command:

crossdev -s4 --target arm-something-linux-uclibc

Where -s4 is stage 4 which also is the default setting. --target shows the client Arch for which the build is going to happen. This is defined in client's CHOST variable in /etc/make.conf

If toolchain fails to build, try to use older and more stable versions.

Remember to symlink /etc/make.profile to the appropriate directory under /usr/portage/profiles.

If you want to cross-compile packages for other platform, some compilation variables must be set correctly. Generally speaking, the following variables is what you have to set correctly.

ARCH="arm" #The target platform
CHOST="arm-something-linux-uclibc" # this is the machine which you want the cross-compiled packages to run on.
CBUILD="i686-pc-linux-gnu" #this is the machine which cross-compiles the packages for other platforms, usually is an x86 machine.
CFLAGS="-O2 -pipe" #take a look at Safe_Cflags for safe CFLAGS.
CXXFLAGS="${CFLAGS}" #normally the same as CFLAGS.

Third: emerging packages that you need inside your cross-environment

ROOT=/usr/arm-something-linux-uclibc/ emerge somepackage

For cross-compiling the Linux kernel, issue the following command:

make ARCH=arm CROSS_COMPILE=arm-something-linux-uclibc-

Cross compile i686 on x86_64 slave nodes over distcc

Note: The following assumes that you have already set up distcc, the same way that you would with a homogeneous network

On the x86_64 (slave/server) systems: Set up the crossdev environment

emerge crossdev
crossdev -t i686-pc-linux-gnu

note: Gentoo forces the ~arch version of the cross-compiler toolchain, better is to pass the exact versions to install as parameters

crossdev -t i686-pc-linux-gnu --b  2.16.1-r3 --g 4.1.1-r3 --k 2.6.17-r2 --l 2.4-r4 

please change the version numbers so they match the i686 (client) version actually in use. --b <binutils version> --g <gcc version> --k <kernel-headers version> --l <glibc version>

On the i686 (client) systems: Wrap generic gcc commands so that the proper CHOST version is called instead.

cd /usr/lib/distcc/bin
rm -f cc gcc c++ g++
echo '#!/bin/bash' >i686-pc-linux-gnu-gcc-wrapper
echo 'exec /usr/lib/distcc/bin/i686-pc-linux-gnu-g${0:$[-2]} "$@"' >>i686-pc-linux-gnu-gcc-wrapper
chmod a+x i686-pc-linux-gnu-gcc-wrapper
ln -s i686-pc-linux-gnu-gcc-wrapper cc
ln -s i686-pc-linux-gnu-gcc-wrapper gcc
ln -s i686-pc-linux-gnu-gcc-wrapper c++
ln -s i686-pc-linux-gnu-gcc-wrapper g++

That's all there is to it.

Similiar CPU

If you want to cross compile for the same arch (but for a different CPU) you can cheat portage and swap your make.conf (with some script) and then build binpackages into another directory.

  1. emerge crossdev
    • crossdev --help
  2. mkdir -p /usr/local/portage
  3. Add or extend PORTDIR_OVERLAY in /etc/make.conf
    • PORTDIR_OVERLAY = "/usr/local/portage"
  4. crossdev -t <ARCH> (or crossdev-stable -t <ARCH>)
    • For list of valid ARCH see: crossdev -t help (or crossdev-stable -t help)

See also

External links

This article is still a Stub. You can help Gentoo-Wiki by expanding it.

Retrieved from ""

Last modified: Fri, 03 Oct 2008 13:48:00 +0000 Hits: 33,518