Cross compiling static C hello world for Android using arm-linux-gnueabi-gcc

corbin picture corbin · Feb 17, 2012 · Viewed 60.1k times · Source

I want to build a static hello world from C using arm-linux-gnueabi-gcc as opposed to using the NDK standalone toolchain or Codesourcery for that matter.

In Ubuntu...

I have done the following:

sudo apt-get install gcc-arm-linux-gnueabi

I created a hi.c like this:

#include <stdio.h>

int main(int argc, char** argv) {
   printf("hello world\n");
   return 0;
}

I have compiled it like this:

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

I ran it on an emulator like this:

adb push hi /data/hi
adb shell /data/hi

But, I get this:

[1]   Illegal instruction     /data/hi

What step have I forgot? Based on past experience this "should" have worked, but I obviously messed this up.

Answer

Leo picture Leo · Feb 20, 2012

Try specifying the architecture/cpu. It sounds like the compiler is creating code with a higher architecture version than the emulator can handle.

This might work:

arm-linux-gnueabi-gcc -static -march=armv5 hi.c -o hi