Crossdev
From Gentoo Linux Wiki
| Please format this article according to the Style Guidelines and Wikification suggestions, then remove this notice {{Wikify}} from the article.
Reason(s):
|
Crossdev is a script which automates the building of cross-compiling toolchains. It is in the sys-devel/crossdev package.
Contents |
[edit] What is cross compiling?
Cross-compiling is building binaries for one architecture (the target) on another (the host).
Reasons you may wish to do this include:
- You are an embedded developer, and cannot fit a native toolchain on an embedded system.
- You are porting Gentoo to a new architecture, and need to cross-compile a stage 1 system to bootstrap.
- You are building binaries against a different C library. While this is not cross-compiling, a different target tuple can be used to accomplish this.
- You need 32 bit library on a 64bit system and don't want to build a complete chroot environment
[edit] Why do we need crossdev?
Gentoo created the crossdev script to automate the complex process of building a cross compiler. While it is not error-free, it does not require the extensive GNU lore and trial and error required by building it from scratch. A lot of the build options are set up for you, meaning that the developers have figured it out already so you don't have to.
[edit] Installation and Use
The first thing that is necessary is the creation of an overlay. If you have one, emerge the script:
This will provide you with the crossdev script. This script automates the steps necessary to build a toolchain. These steps are, in short:
- binutils: Build a cross-binutils, which links and processes for the target architecture.
- linux-headers: Install a set of C library and kernel headers for the target architecture.
- libc-headers: Additional header files
- gcc-stage-1: Build a basic (stage 1) gcc cross-compiler. This will be used to compile the C library. It will be unable to build anything almost else (because it can't link against the C library it doesn't have).
- libc: Build the cross-compiled C library (using the stage 1 cross compiler).
- gcc-stage-2: Build a full (stage 2) C cross-compiler.
All cross toolchains will be kept locally in the overlay, separate from native tools.
source /usr/portage/local/layman/make.conf PORTDIR_OVERLAY="/usr/local/portage $PORTDIR_OVERLAY"
The script is used like:
This will build a cross-compiling toolchain for PowerPC machines.
By default, the newest stable version of the binutils, libraries, and C compiler will be used. It is quite often the case they will not compile themselves through the entire build process. Less bleeding edge versions can be specified with additional flags:
--b 2.17 # specifies the version of binutils --g 4.2.3 # specifies the version of gcc --l 0.98.3-r2 # specifies the version of the tuple-specified libc --k 2.6.25 # specifies the version of the kernel headers
It is recommended trying older versions, particularly of gcc, if the script fails.
If you want to remove a toolchain, use the clean flag:
This will unmerge the packages created by crossdev.
[edit] Known problems
Error while building GCC stage 1: "Building GCC requires GMP 4.1+ and MPFR 2.3.0+."
[edit] pkg-config problems
There are problems where build program does not take into account using the correct pkg-config. To correct this you need to also install a pkg-config wrapper for your target. Taken the followin from the gentoo documention found here
Here is also the script that gentoo doc uses put here for easy refrence
#!/bin/sh
CTARGET=${0%-pkg-config}
SYSROOT="/usr/${CTARGET}"
export PKG_CONFIG_LIBDIR="${SYSROOT}/usr/lib/pkgconfig"
unset PKG_CONFIG_PATH PKG_CONFIG_ALLOW_SYSTEM_CFLAGS PKG_CONFIG_ALLOW_SYSTEM_LIBS
exec pkg-config "$@"
Don't forget to chmod + x the file or it won't be found. I also had a problem CTARGET not being set right so you might have to change it as well.
[edit] Problem with libtool
I found out there problem with libtool you can read about it here http://metastatic.org/text/libtool.html
[edit] Supported Architectures
| Fix me: Is there a list somewhere? |
Currently, every GCC-tuple (e.g. i686-pc-linux-gnu) for which Gentoo has been ported is supported. Additional architectures, of course, have their own patches, bugs, hacks, and specific necessary versions of all the tools. Several are already listed on this wiki in different articles.
Notable architectures include:
- i686-pc-linux-gnu: The default x86 tuple for PCs.
- x86_64-pc-linux-gnu: The default tuple for 64-bit x86 Machines (such as the AMD 64 and IA64 architectures).
- powerpc-unknown-linux-gnu: Support for PowerPC PCs, such as Apple Macintoshes.
- arm-unknown-linux-gnu: Support for embedded devices based on ARM chips.
- arm-softfloat-elf: For embedded devices with ARM chips without hardware floats
- arm-elf: For embedded devices with ARM chips with hardware floats
- i686-pc-mingw32: Supports cross-compiling for 32-bit Windows (toolchain based on mingw32).
- i686-w64-mingw32: Supports cross-compiling for 32-bit Windows (toolchain based on mingw64).
- x86_64-w64-mingw32: Supports cross-compiling for 64-bit Windows (toolchain based on mingw64).
- avr: Supports cross-compiling for Atmel AVR-MCU's.
[edit] Known Working Architecture Matrix
The following sections are by no means exhaustive. However, these are known working combinations of versions of some of the more common architectures.
[edit] Power PC Architecture
| Fix me: crossdev -t powerpc-unknown-linux-gnu --g 4.3.1 |
[edit] ARM Architecture
| Fix me: crossdev -t arm-unknown-linux-gnu --b 2.19.1 --g 4.3.3 --l 2.9_p20081201-r1 --k 2.6.28-r1 |
[edit] AVR Architecture
first build without headers
| Fix me: crossdev -v --target avr --gcc 4.3.3 --binutils 2.19.51.0.2 --libc 1.6.4 -s1 --without-headers |
then the rest
| Fix me: crossdev -v --target avr --gcc 4.3.3 --binutils 2.19.51.0.2 --libc 1.6.4 |
I also needed some workaround so that the linking works like expected
| Fix me: ln -s /usr/i686-pc-linux-gnu/avr/lib/ldscripts /usr/avr/lib/ldscripts |
hopefully this bug gets fixed somewhat soon. Also, the directory structure might vary for your needs, e.g. x86_64 instead of i686. At least this combination compiled nicely for me (13. April 2009)
24. July 2009: Works under amd64 too! Use:
| Fix me: ln -s /usr/x86_64-pc-linux-gnu/avr/lib/ldscripts /usr/avr/lib/ldscripts |
Seems as if this Bug will not get fixed! -> http://bugs.gentoo.org/show_bug.cgi?id=147155#c30
[edit] MIPS Architeture
[edit] MIPSel Specific
Looks that MIPsel have some problems with the last binutils/gcc
| Fix me: crossdev -t mipsel-linux-uclibc --b 2.19.1 --g 3.4.6-r2 |