Nathan Coulson
Linux to Ubuntu Cross Compiler
This has been tested on Ubuntu 14.04, but should also work for debian as well. To keep it generic, I use the name x86_64-ubuntu-linux-gnu, but if you use more then one target, you can name it x86_64-ubuntu1404-linux-gnu, or any other similar variation.Modern versions of ubuntu and debian use multiarch, where libraries can be found in /usr/lib/x86_64-linux-gnu and /usr/lib/i386-linux-gnu. Recent versions of gcc and binutils have been patched to understand this filestructure
This could potentially be done for rpm distro's as well using rpm distro's as well using febootstrap version 2
Downloads & Requiraments
- Binutils 2.24 - ftp://ftp.gnu.org/gnu/binutils/binutils-2.24.tar.bz2
- GCC 4.8.1 - ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.1/gcc-4.8.1.tar.bz2
- debootstrap - [available from ubuntu/debian repo's]
Installing the sysroot
After the sysroot is created with debootstrap, it could be transferred to another pc.- apt-get install debootstrap
- install -d -m755 /usr/x86_64-ubuntu-linux-gnu
- debootstrap trusty /usr/x86_64-ubuntu-linux-gnu/sysroot
- Debian 6.0 - squeeze
- Debian 7 - jessie
- Ubuntu 13.04 - raring
- Ubuntu 13.10 - saucy
- Ubuntu 14.04 - trusty
- See /usr/share/debootstrap/scripts for all options
- #Add Additional Architectures
- dpkg --add-architecture i386
- #Edit /usr/x86_64-ubuntu/linux-gnu/sysroot/etc/resolv.conf if you want to add any dns servers (by default, only 127.0.0.1 is listed)
- chroot /usr/x86_64-ubuntu-linux-gnu/sysroot "apt-get install libc6:i386 libc6-dev:i386 libc6:amd64 libc6-dev:amd64"
- # Change all symlinks to relative symlinks. This must be run anytime you install/updates software in the chroot
- do
- test "$(readlink $x | cut -c 1)" == "/" &&
- ln -svfn $(python -c "import os.path; print os.path.relpath(\"$(dirname /usr/x86_64-ubuntu1204-linux-gnu/$(readlink $x))\", \"$(dirname $x)\")")/$(basename $(readlink $x)) $x
- done
Binutils
- mkdir binutils-build
- cd binutils-build
- ../configure --prefix=/usr --target=x86_64-ubuntu-linux-gnu --with-sysroot=/usr/x86_64-ubuntu-linux-gnu --enable-gold=yes --enable-ld=no
- make
- make install
GCC
- mkdir gcc-build
- cd gcc-build
- ../configure --prefix=/usr --target=x86_64-ubuntu-linux-gnu --with-sysroot=/usr/x86_64-ubuntu-linux-gnu --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-languages=c,c++ --enable-long-long --enable-multiarch
- make
- make install
Managing the sysroot (updating and installing software
To enter the sysroot, you can use chroot /usr/x86_64-ubuntu-linux-gnu/sysroot. At this point, you can use apt-get to manage your software.By default, only the main repository is added (without updates/security). You can add any additional repositories you desire by adding the following to /usr/x86_64-ubuntu-linux-gnu/sysroot/etc/apt
- deb http://archive.ubuntu.com/ubuntu saucy main
- deb http://archive.ubuntu.com/ubuntu saucy-updates main
- deb http://archive.ubuntu.com/ubuntu saucy-security main
- deb http://archive.ubuntu.com/ubuntu saucy universe
- deb http://archive.ubuntu.com/ubuntu saucy-updates universe
- deb http://archive.ubuntu.com/ubuntu saucy-security universe
- deb http://archive.ubuntu.com/ubuntu saucy multiverse
- deb http://archive.ubuntu.com/ubuntu saucy-updates multiverse
- deb http://archive.ubuntu.com/ubuntu saucy-security multiverse
- deb http://archive.ubuntu.com/ubuntu saucy restricted
- deb http://archive.ubuntu.com/ubuntu saucy-updates restricted
- deb http://archive.ubuntu.com/ubuntu saucy-security restricted