Cross-compiler

From Pandora Wiki
Revision as of 05:00, 17 December 2010 by Myownlittlworld (talk | contribs) (Raised section levels)
Jump to: navigation, search

One of the ways to compile your applications to the ARM architecture is through a cross-compiler.

Using the SDK-Installer

Cpasjuste on the GP32X forums has made a nice script to get a build environment and libraries installed on Ubuntu/Debian systems. Download links and a brief explanation can be found in this thread.

Alternatively you could try the easy to set up environment described on DJWillis' blog which is suitable for 32bit Linux. The process is explained, and corrected slightly (for Debian Squeeze systems), below.

DJWillis' Cross Compiler, Redux

DJ-Willis's cross-compiling toolchain page is really awesome, but it has a few holes I'd like to patch up in this guide. Here, we'll be creating a chroot jail to install the toolchain on with a Debian Squeeze system. This will allow you to use DJ Willis's toolchain without mucking with your normal system at all. Of course, it's obviously overkill, but, hey, what's technical insight without it?

The commands are detailed exactly as you'll need to enter them, from start to finish, to compile Pandora native apps on your host system. They'll run really well on the Pandora, but they won't run on your host. To do that, you'll need to compile them for the host system, which is a different, but much simpler, process.

Resources

The following are generic resources you might want to read up on to make better sense of the instructions that follow.

Instructions

The following instructions are for a (Debian) host system that you have root access to. The system-inside-a-system you're building will probably take about 1 GiB of hard-drive space.

$ cd ~ 
$ mkdir pandora_cross_compiler
$ su -c "apt-get install debootstrap chroot" # get the dependencies
$ su -c "debootstrap squeeze pandora_cross_compiler" # see the debootstrap wiki
$ su -c "LANG=C chroot pandora_cross_compiler /bin/bash" # see the chroot wiki
# apt-get install bzip2 unzip curl libmpfr-dev
# ln -s /usr/lib/libmpfr.so /usr/lib/libmpfr.so.1
# cd ~
# wget http://djwillis.openpandora.org/toolchains/20100611-i686-linux-armv7a-linux-gnueabi-toolchain-openpandora.tar.bz2 http://djwillis.openpandora.org/toolchains/DisplayImage.zip
# tar -C / -xjf 20100611-i686-linux-armv7a-linux-gnueabi-toolchain-openpandora.tar.bz2
# unzip DisplayImage.zip
# . /usr/local/angstrom/arm/environment-setup
# arm-angstrom-linux-gnueabi-gcc -Wall DisplayImage.c -o DisplayImage -l SDL
# exit

Congratulations! You just compiled an ARM-based executable! It won't run on the Intel 32-bit system you're testing it on! To see it not run on your normal system, run:

$ su -c "cp pandora_cross_compiler/root/DisplayImage .; cp pandora_cross_compiler/root/test.bmp ."
$ su -c "chown (your user):(your group) DisplayImage test.bmp"
$ ./DisplayImage

It won't work. It's not supposed to work. You compiled it for the Pandora. If you have a Pandora, copy it to the Pandora and it should work.

To get back into your chroot jail to compile more programs that you can copy then back into your normal system and your Pandora, you'll just need to run:

$ su -c "LANG=C chroot pandora_cross_compiler /bin/bash"

And Bam! You're back in the chroot.

Consider using QEmu to create an ARM VM for testing the programs. See the Pandora Press link for those instructions. Also see the comments for getting the QEmu image to run in Linux.

Manual Installation

If you want a bit more control, Code-Sourcery hosts a bunch of cross-compiling suites for various platforms on their site, some editions have to be paid for, but they do have "lite" editions without support that are completely free.

Head up onto here. The recommended release at time of writing is 2009q3.

Installers are available for Linux and Windows. Alternatively, download and unpack the tarball, then add the bin directory to your path.

Example: Setting up a cross compiler using Code Sourcery, and doing so inside a VM

Skeezix makes some notes in his blog about setting up CodeSourcery's prebuilt toolchain in a VM very quickly.