Today I finally managed to do it using CodeSourcery's cross compiler on linux. A cross compiler is something which allows you to compile on one architecture (the host) and run the executable binary on another (the target). In this case, the host is the linux machine where we'll install the toolchain (linux intel x86) and android phone is the host (arm).
- Download CodeSourcery's toolchain installer for GNU/Linux target for IA32 host
- Install it: sh arm-2008q3-72-arm-none-linux-gnueabi.bin
- The toolchain provides the cross compiler arm-none-linux-gnueabi-gcc. You need to put it's directory in your $PATH. Once you have the toolchain, you can easily compile your hello world program: arm-none-linux-gnueabi-gcc -o hello -static hello.c
- Copy the binary to your phone and run it from an adb shell prompt: ./hello
Points to note:
- The above binary is static, that is it does not use the phone's libc libraries. Android ships with its own trimmed down version of libc, called bionic. Next I'll be trying to compile and run using bionic libc, so that I don't have to compile statically
- The above steps do not use the toolchain in the android source code. I'll try later to cross compile using that.