1

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 instruction"

Any ideas on how I can run my program on my phone?

2 Answers 2

5
+50

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

Sign up to request clarification or add additional context in comments.

Comments

2

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 

1 Comment

I tried your answer, and on my desktop, It should be CC -o foo.o -c foo.c -fPIE -pie and adb shell /data/local/tmp/foo.o Reference: (stackoverflow.com/questions/24818902/…)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.