Procedure for compiling native linux binaries for Android using dynamic linking and the bionic libc


Sourcery g++ can be used out of the box to compile static binaries with glibc, but to use dynamic linking with bionic libc you also need a special crt0.o.
A simple function wrapper that most descriptions of this process uses is not sufficient as it won't pass on argc/argv and return correctly.

Stuff needed:
Sourcery G++ (gnu/linux target)
crt0.s
A simple compile script
You also need the libs from your phone's "/system/lib" use 'adb pull' or get them from an update package or a yaffs2 dump

For my HTC Hero, the following compile command was used:

First build crt0.o:

arm-none-linux-gnueabi-gcc -c crt0.s

Compile my screenshot util with:
arm-none-linux-gnueabi-gcc -march=armv6j -mcpu=arm1136jf-s -O3 -c screenshot.c
arm-none-linux-gnueabi-ld --entry=_start --dynamic-linker /system/bin/linker -nostdlib \
-rpath /system/lib -rpath ~/android/system/lib -L ~/android/system/lib -lc screenshot.o crt0.o -o screenshot

Screenshot util:
Full resolution version: source ARM binary
Half resolution (scaler) version: source ARM binary
Util for converting output to 8-bit raw RGB data stream: fb2raw.c
Tools for converting stream to images and avi: screenshot_utils.tar
Example output: Full resolution test  Half-size (scaler)


Eirik (Signoff The Sourcerer) Risholm <signoff@bensin.org>