HOWTO Cross Compile
From Gentoo Linux Wiki
| 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.
- Gentoo Cross Development Guide (Deprecated, View the Embedded Handbook now)
- Gentoo Cross-Compiling with Distcc
Contents |
[edit] Introduction
From mingw.org: 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)."
[edit] Examples
[edit] 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:
PORTDIR_OVERLAY="/usr/local/portage"
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 ACCEPT_KEYWORDS="ppc" 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-
[edit] Cross compile i686 on x86_64 slave nodes over distcc
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.
[edit] 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.
- emerge crossdev
- crossdev --help
- mkdir -p /usr/local/portage
- Add or extend PORTDIR_OVERLAY in /etc/make.conf
- PORTDIR_OVERLAY = "/usr/local/portage"
- crossdev -t <ARCH> (or crossdev-stable -t <ARCH>)
- For list of valid ARCH see: crossdev -t help (or crossdev-stable -t help)
[edit] See also
- HOWTO MinGW
- HOWTO MinGW and SDL CrossCompiling -- Cross-compiler installation instructions (for building Windows (Win32) binaries)
- HOWTO MinGW and Qt4 -- Minimal instructions (cross-compiler for Windows binaries)
[edit] External links
- MinGW FAQ -- How can I build a cross compiler?
- How to cross compile to MinGW
- mingw-cross-howto -- Steps to build a Linux hosted MinGW cross-compilation environment
- Cross-compiling on Windows for Linux -- Compiling Linux binaries (x86/x86-64) under Windows
- Vapier's X-Compile Howto
- Another Observation * link broken, 2006-12-20
- Gentoo Cross Development Guide * deprecated, please go Embedded Handbook
This article is still a Stub. You can help Gentoo-Wiki by expanding it.
