Android

Compile native directly on Android phone

This is just a small sneak preview – but it will take a bit to release the whole thing.

I have managed to cross-compile gcc-4.3.5 (and dependencies) for ARM platforms – which allow to directly compile C code on the any ARMv5 (or newer) Android phone.

It is based on buildroot environment and no library dependency exists between it and Android libs. It also uses its own ld.so preloader, meaning that in the future, I would like to have a bunch of Linux tools running directly on the phone, but without the need to have the dependencies statically linked into each environment.

Some outputs:

* Compiling Hello World using the native compiler:

Compiling and ldd command on Android phone

Compiling and ldd command on Android phone

* readelf -A on the native compiler

readelf -A gcc on Android phone

readelf -A gcc on Android phone

* Output of gcc -v

[root@arc]/sdcard# gcc -v
Using built-in specs.
Target: arm-unknown-linux-uclibcgnueabi
Configured with: /home/viulian/buildroot-2010.08/output/toolchain/gcc-4.3.5/configure --prefix=/usr --build=i686-pc-linux-gnu --host=arm-unknown-linux-uclibcgnueabi --target=arm-unknown-linux-uclibcgnueabi --enable-languages=c --with-gxx-include-dir=/usr/include/c++ --disable-__cxa_atexit --with-gnu-ld --disable-libssp --disable-multilib --disable-tls --enable-shared --enable-threads --disable-decimal-float --with-float=soft --with-abi=aapcs-linux --with-arch=armv5te --with-tune=xscale --disable-largefile --with-pkgversion='Buildroot 2010.08' --with-bugurl=http://bugs.buildroot.net/ : (reconfigured) /home/viulian/buildroot-2010.08/output/toolchain/gcc-4.3.5/configure --prefix=/usr --build=i686-pc-linux-gnu --host=arm-unknown-linux-uclibcgnueabi --target=arm-unknown-linux-uclibcgnueabi --enable-languages=c --with-gxx-include-dir=/usr/include/c++ --disable-__cxa_atexit --with-gnu-ld --disable-libssp --disable-multilib --disable-tls --enable-shared --enable-threads --disable-decimal-float --with-float=soft --with-abi=aapcs-linux --with-arch=armv5te --with-tune=xscale --disable-largefile --with-pkgversion='Buildroot 2010.08' --with-bugurl=http://bugs.buildroot.net/
Thread model: posix
gcc version 4.3.5 (Buildroot 2010.08)

* Compiling “Hello World” on the phone itself and showing the ldd command executed on the native executable:

[root@arc]/sdcard/work/test# cat hello.c
#include

int main(int argc, char** argv) {
        printf("Hello world!\n");
}
[root@arc]/sdcard/work/test# time gcc hello.c -o /system/var/hello

real    0m0.227s
user    0m0.110s
sys     0m0.060s
[root@arc]/sdcard/work/test# /system/var/hello
Hello world!
[root@arc]/sdcard/work/test# ldd /system/var/hello
        libc.so.0 => /lib/libc.so.0 (0x2aab9000)
        ld-uClibc.so.0 => /lib/ld-uClibc.so.0 (0x2aaab000)
[root@arc]/sdcard/work/test#

I am still testing it, and will release it when ready!

20 Comments

  1. Have been compiled php, useful, and as soon as possible to release the GCC to support you. (I come from China, the text used Google Translate)

  2. Not interested in php mysql or pgsql compile on?

  3. Comment by post author

    Seems Google Translate does a good job 🙂

    Yes, I will focus on MySql next – maybe I will do it static this one and not delivering with gcc but in the php bundle with lighttpd.

  4. You can not download the mysql?

  5. Comment by post author

    It is not ready yet ..

    I have the binaries but it is still difficult to install and so on, I will have to polish it – and maybe try to compile version 5.5 (since this one is 5.1).

    Then I will offer a small application that installs it.

    Sorry … but I just got it to run 🙂 and now all the details are as difficult as it was to compile it.

  6. Want to compile with a php latest version of mysql or pgsql extension, have a database extension that we can at least connect to a remote database. Which is conducive to the testing part of the database procedures.

  7. nginx is a very good open source web server, I hope you can take a look at the address http://nginx.org/.

  8. @viulian
    gcc when released?
    Can send a gcc beta to admin@aite.me you?

  9. Comment by post author

    About gcc and other releases, they are on hold until I sort out one issue with the newer 3.X kernels … I’m sorry, I will put an update once everything is OK.

  10. Greg

    Hi, I want to croos compile gcc for Android and I’m quite lost. Could you post the steps to follow in order to achieve this? Thank you I really appreciate it!

  11. Jay

    I am also waiting for gcc, and I also think it would be great if you would post some notes helping other people to get started with porting it. Then maybe a small group can maintain gcc for Android and support all of the CPU architectures and devices.

    Porting gcc is an important step towards fleshing out the Linux commands and other programs on Android for those of us who want them. Now that tablet computers with fast CPUs, and large memory and flash disks are becoming more common, I expect that more people will want this.

  12. drinxtir

    I’m waiting for a release. I’m hoping for, eventually, a whole linux suite of tools for these phones/tablets.

  13. xiling

    Can you compile the gnu binutils for android?Thank you very much~
    In Android Market,there is a app named c4droid which plugin has gcc version 4.6.1 is available.

  14. Comment by post author

    I will try … but very busy recently …

  15. xiling

    It’s doesn’t matter,Go ahead…
    (my English is poor)

  16. markblaze

    Iv been using the gcc port for android that’s posted here http://rwiki.sciviews.org/doku.php?id=getting-started:installation:android and it seems to work ok for compiling small things like secure-delete 7zip etc. With that port I usually just extract it onto my sd-ext partition seen as its a cheap phone and I have with not much space on my /data but as long as I have c4droid and the gcc plugin installed it can be run from terminal emulator to compile. Just thought id link you to that incase you can combine it with what youv compiled so far to make things a little easier for you. looking forward to trying out your port onced you’ve got it ready. Good luck viulian and keep up the good work bud 🙂

  17. Gabriel

    Any progress on this? My S3 arrives in a couple of days and I want something like this. I’m trying out Android. I have gcc on my jailbroken iPhone and couldn’t live without a decent compiler on Android.

  18. I too have been using c4droid’s gcc 4.7.1 plugin, it is available for free on android market as API. Then copy or link to it from /data/local/bin.

  19. Val3r10

    I’m trying to compile unzip v6.0 (http://www.info-zip.org/UnZip.html) because the busybox version is too limited for my needs.
    But I wasn’t able to manage the configure/automake process

    Any clue or how-to with such small and simple source codes ?
    Thanks a lot

Leave a Reply