How to run arm binary on Android platform?
I want to run a "hello world" program on Android.
It is written in C, and I tried different cross-compilers.
arm-elf-gcc : when I type "./hello" on my phone with adb I get a "Segmentation Fault". However, arm-elf-gdb runs the hello program normally, without a segmentation fault.
arm-linux-gcc : when I type "./hello" on my phone, I get "Illegal ins开发者_JS百科truction"
Any ideas on how I can run my program on my phone?
This tutorial seems to explain quite well how to build and debug native C applications for Android: http://betelco.blogspot.com/2010/01/buildingdebugging-android-native-c.html
First, make sure you have the NDK:
http://developer.android.com/tools/sdk/ndk/index.html
Here is the easiest way to compile a C binary for your phone:
http://developer.android.com/tools/sdk/ndk/index.html
http://www.kandroid.org/ndk/docs/STANDALONE-TOOLCHAIN.html
Usually $NDK(may be different) =
Linux:
/home/<user>
/android-ndk
Mac OS X:
/Users/<user>
/android-ndk
In Terminal:
# create tool-chain - one line
$NDK/build/tools/make-standalone-toolchain.sh --platform=android-3 --install-dir=/tmp/my-android-toolchain
# add to terminal PATH variable
export PATH=/tmp/my-android-toolchain/bin:$PATH
# make alias CC be the new gcc binary
export CC=arm-linux-androideabi-gcc
# compile your C code(I tried hello world)
$CC -o foo.o -c foo.c
# push binary to phone
adb push foo.o /data/local/tmp
# execute binary
adb /data/local/tmp/foo.o
精彩评论