Differences between revisions 1 and 40 (spanning 39 versions)
Revision 1 as of 2006-07-24 13:39:25
Size: 4133
Editor: ?MarcusBetter
Comment:
Revision 40 as of 2013-12-19 23:25:17
Size: 3229
Editor: ?shawnlandden
Comment: this is obsoleted by the multiarch cross toolchains
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= Building a Cross Compiler = #language en
~-[[DebianWiki/EditorGuide#translation|Translation(s)]]: none-~
----
<<TableOfContents()>>
Line 3: Line 6:
This document will help you build Debian packages of a cross-compilation toolchain. It is based on [http://psas.pdx.edu/DebianCrossCompilerHowto a HOWTO] by Josh Triplett, with his kind permission. = Installing a Cross Compiler =
Line 5: Line 8:
Commands you need to run as root assume you have already set up sudo on your system. This document will help you obtain Debian packages of a cross-compilation toolchain. It is based on [[http://psas.pdx.edu/DebianCrossCompilerHowto|a HOWTO]] by Josh Triplett, with his kind permission.
Line 7: Line 10:
We will be building a cross-compiler from the gcc-4.1 package. Specific version numbers for packages are listed as VERSION; substitute the version number of the latest package in unstable (or testing). Note that most cross-toolchain combinations you might actually want within Debian are built by the Embedded Debian Project, so you may well just be able to apt-get what you need on their Toolchains page: http://www.emdebian.org/crosstools.html
Line 9: Line 12:
== Build a cross-compilation toolchain == We'll say that again: '''MOST PEOPLE SHOULDN'T BE BUILDING THEIR OWN CROSS-TOOLCHAIN - THEY SHOULD JUST INSTALL A PRE-BUILT ONE LIKE ANY OTHER PACKAGE'''.
Line 11: Line 14:
=== Create a working directory === == To install a prebuilt cross compiler ==

=== What if I have an Ubuntu system or want to do multiarch-style crossbuilding? ===

If you have an Ubuntu system, cross-toolchains are included (from 10.10/maverick onwards). From Quantal/ onwards there is a crossbuild-essential-<arch> convenience package to install cross toolchains, cross-pkgconfig and (multiarch) cross-libc. So simply installing crossbuild-essential-armhf, or crossbuild-essential-arm64 will get you all the stuff you need. (multiarch for the architecture you want to build for must be enabled, with dpkg --add-architecture <arch> (e.g. armhf))

Prior to quantal there are just cross-toolchain packages which install the cross-toolchain and default compiler links. apt-get install arm-linux-gnueabi-gcc (for armel) or arm-linux-gnueabihf-gcc (for armhf). These toolchains search multiarch library and header paths by default so are suitable for multiarch crossbuilding.

For other architectures, or if you have a Debian system you should get toolchains from Emdebian. These toolchains search in the 'dpkg-cross' cross-lib/headers paths, not the new multiarch paths, so are not very useful for multiarch cross-building.

Debian multiarch-ready cross-toolchains for armhf and armel are available here: http://emdebian.org/~thibg/repo/pool/main/g/gcc-4.7/ Work is underway to integrate cross-toolchains properly into debian: [[http://wiki.debian.org/MultiarchCrossToolchains|multiarch-ready Debian cross-toolchains]].


=== Installing cross-toolchains from Emdebian ===

Add the Emdebian keyring from Debian before you start.
Line 13: Line 31:
mkdir -p ~/src/cross-toolchain
cd ~/src/cross-toolchain
apt-get install emdebian-archive-keyring
Line 17: Line 34:
=== Some useful variables ===
These will be used in the commands in this document.
Replace "arm" with the architecture for which you are building a cross-compiler.
Add two apt sources, one for your normal mirror and one for Emdebian:
Line 21: Line 36:
ARCH=arm deb http://ftp.XX.debian.org/debian squeeze main
deb http://www.emdebian.org/debian squeeze main
Line 24: Line 40:
=== Get the source for binutils and GCC === Create a new file in {{{/etc/apt/sources.list.d/}}} with the above lines.

Use whatever is your normal Debian mirror for the first line which brings in some dependencies which are no longer in Wheezy or unstable.

Now just install your toolchain, e.g. for armel:
Line 26: Line 46:
apt-get source binutils gcc-4.1 apt-get update
apt-get install g++-4.4-arm-linux-gnueabi
Line 29: Line 50:
=== Install Build-Depends ===
{{{
sudo apt-get build-dep binutils gcc-4.1
}}}
Emdebian also maintain scripts which effectively do what this page describes. Take a look at the DebianPts:buildcross package from Debian experimental, which will build a whole range of toolchains.
Line 34: Line 52:
Note that gcc-4.1 may have build-dependencies that apt-get can't figure out; this is not a problem, just make sure you install all the ones that apt-get understands. Unfortunately, apt-get build-dep may give an error if such a situation arises; in this case, take the list of packages apt-get provided before giving an error, and install them using "sudo apt-get install pkg1 pkg2 pkg3 ...". '''Most users do not need to build the cross-compiler'''
Line 36: Line 54:
=== Install fakeroot ===
fakeroot allows you to build packages without being root.
{{{
sudo apt-get install fakeroot
}}}
Line 42: Line 55:
=== Install dpkg-cross ===
dpkg-cross adds cross-compilation support to some of the basic Debian package tools. dpkg-cross can also convert packages designed for the target architecture into packages usable for cross-compilation to that architecture.
{{{
sudo apt-get install dpkg-cross
}}}

=== Build and install binutils ===
While still in the binutils directory:
{{{
TARGET=$ARCH-linux-gnu fakeroot debian/rules binary-cross > ../binutils.build 2>&1 || echo 'Build error'
cd ..
sudo dpkg -i binutils-powerpc-linux-gnu_VERSION_HOSTARCH.deb
}}}

=== Convert library packages ===
You will need cross-compilation packages for various libraries; dpkg-cross can convert native packages for the target architecture into packages usable for cross-compilation.
{{{
wget http://ftp.XX.debian.org/debian/pool/main/g/glibc/libc6-dev_VERSION_$ARCH.deb
wget http://ftp.XX.debian.org/debian/pool/main/g/glibc/libc6_VERSION_$ARCH.deb
wget http://ftp.XX.debian.org/debian/pool/main/l/linux-kernel-headers/linux-kernel-headers_VERSION_powerpc.deb
dpkg-cross -a $ARCH -b l*.deb
sudo dpkg -i l*$ARCH-cross*.deb
}}}

=== Build and install GCC ===
Now that you have all the necessary prerequisites, you can build a cross-compiling GCC.
{{{
cd gcc-VERSION
export GCC_TARGET=$ARCH
debian/rules control
dpkg-buildpackage -us -uc -rfakeroot -b > ../gcc.build 2>&1 || echo 'Build error'
cd ..
sudo dpkg -i *-4.0-$ARCH-linux-gnu*.deb *-$ARCH-cross_4.0*.deb
}}}

== Test the cross-compile environment ==
=== Test compilation ===
Create a file "hello.c", containing the following code:
{{{
#include <stdio.h>

int main()
{
    printf("Hello cross-compiling world!\n");
    return 0;
}
}}}

Compile it statically with the new cross-compiler.
{{{
$ARCH-linux-gnu-gcc -static hello.c -o hello
}}}

Check the binary's type with "file".
{{{
file hello
}}}

You should see something like:
{{{
hello: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), for GNU/Linux 2.2.0, statically linked, not stripped
}}}
for the PowerPC architecture.

=== Install qemu ===
qemu is an emulator for various architectures. It supports both whole-system emulation as well as single-program emulation with system-call conversion.
{{{
sudo apt-get install qemu
}}}

=== Run the test program with qemu ===
To run the test program with qemu, just prefix it with "qemu-$ARCH" (assuming of course that your architecture is supported by qemu).
{{{
qemu-$ARCH ./hello
}}}

You should see:
{{{
Hello cross-compiling world!
}}}
----
CategoryEmdebian

Translation(s): none


Installing a Cross Compiler

This document will help you obtain Debian packages of a cross-compilation toolchain. It is based on a HOWTO by Josh Triplett, with his kind permission.

Note that most cross-toolchain combinations you might actually want within Debian are built by the Embedded Debian Project, so you may well just be able to apt-get what you need on their Toolchains page: http://www.emdebian.org/crosstools.html

We'll say that again: MOST PEOPLE SHOULDN'T BE BUILDING THEIR OWN CROSS-TOOLCHAIN - THEY SHOULD JUST INSTALL A PRE-BUILT ONE LIKE ANY OTHER PACKAGE.

To install a prebuilt cross compiler

What if I have an Ubuntu system or want to do multiarch-style crossbuilding?

If you have an Ubuntu system, cross-toolchains are included (from 10.10/maverick onwards). From Quantal/ onwards there is a crossbuild-essential-<arch> convenience package to install cross toolchains, cross-pkgconfig and (multiarch) cross-libc. So simply installing crossbuild-essential-armhf, or crossbuild-essential-arm64 will get you all the stuff you need. (multiarch for the architecture you want to build for must be enabled, with dpkg --add-architecture <arch> (e.g. armhf))

Prior to quantal there are just cross-toolchain packages which install the cross-toolchain and default compiler links. apt-get install arm-linux-gnueabi-gcc (for armel) or arm-linux-gnueabihf-gcc (for armhf). These toolchains search multiarch library and header paths by default so are suitable for multiarch crossbuilding.

For other architectures, or if you have a Debian system you should get toolchains from Emdebian. These toolchains search in the 'dpkg-cross' cross-lib/headers paths, not the new multiarch paths, so are not very useful for multiarch cross-building.

Debian multiarch-ready cross-toolchains for armhf and armel are available here: http://emdebian.org/~thibg/repo/pool/main/g/gcc-4.7/ Work is underway to integrate cross-toolchains properly into debian: multiarch-ready Debian cross-toolchains.

Installing cross-toolchains from Emdebian

Add the Emdebian keyring from Debian before you start.

apt-get install emdebian-archive-keyring

Add two apt sources, one for your normal mirror and one for Emdebian:

deb http://ftp.XX.debian.org/debian squeeze main
deb http://www.emdebian.org/debian squeeze main

Create a new file in /etc/apt/sources.list.d/ with the above lines.

Use whatever is your normal Debian mirror for the first line which brings in some dependencies which are no longer in Wheezy or unstable.

Now just install your toolchain, e.g. for armel:

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

Emdebian also maintain scripts which effectively do what this page describes. Take a look at the buildcross package from Debian experimental, which will build a whole range of toolchains.

Most users do not need to build the cross-compiler


CategoryEmdebian