Cross Compilation

From Android

Jump to: navigation, search

Cross compiling native applications for the G1 can be done using a variety of prebuilt toolchains.

Contents


Embedded Debian (Lenny) toolchain

The Embedded Debian project provides a simple to use toolchain for ARM EABI. To set it up:

apt-get install emdebian-tools
emsetup --arch armel

To compile simple static applications:

arm-linux-gnueabi-gcc -static -o myapp myapp.c

The limitation here is that the application is statically linked. A nicer setup would give us dynamically linked applications. One of the trickier aspects here is that Android uses a custom, tiny libc, (bionic). See below for instructions on getting a working setup for compiling a dynamically-linked program with the prebuilt Android toolchain. Perhaps someone can use those instructions to create a simpler process using the emdebian toolchain.

The desired recipe would look something like the following minimal steps:

1. Install emdebian

2. Download and compile bionic

3. Use something like Andew's agcc, but designed for the emdebian toolchain.

If someone could flesh that out, then that would be very appreciated.

Prebuilt Android toolchain

To get the Android prebuilt toolchain:

1. First download the Android source.

2. That ships with a prebuilt toolchain with a compiler named something like arm-eabi-gcc . It's convenient to get that onto your PATH with something like the following (assuming Android source in $HOME/src/android):

export PATH=$HOME/src/android/prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin

3. Next you'll actually need to compile at least the bionic libc. Without having gone through the effort of doing a minimal compile here, you can do just "make" and wait quite a while for all of Android to get compiled. Note that early on the Makefile will abort if it can't find a JDK that it likes. Presumably no Java is actually needed for the native compilation we're doing here, but again, without having wrestled that out of the Makefiles yet, you can satisfy that requirement with packages from Debian's main repository:

apt-get install openjdk-6-jdk

You may get away with not having any JDK installed by passing BUILD_TINY_ANDROID=true to make, which will build just a few main C/C++-based components (including bionic).

4. Next, there are various flags and things needed to cross-compile an application and properly link it to bionic. Andrew Ross has written a perl script to take the pain away here and with the android toolchain in your PATH you're ready to go. Grab his agcc script and put it into your PATH somewhere, (perhaps in $HOME/bin or so).

5. With all those steps done you can now cross-compile an application dynamically linked to bionic

agcc -o myapp myapp.c
Personal tools