Académique Documents
Professionnel Documents
Culture Documents
About Me
$ cat hello.c int main(int argc, char* argv[]) { Followers (29) More »
return 0;
}
The minimal set of flags to pass to arm-eabi-gcc to get this working is:
$ arm-eabi-gcc -o hello hello.c -Wl,-rpath- Already a member? Sign in
link=/Users/nirnimesh/NIR/android/mydroid/cupcake/out/
target/product/generic/obj/lib -
L/Users/nirnimesh/NIR/android/mydroid/cupcake/out/targ
et/product/generic/obj/lib -nostdlib
/Users/nirnimesh/NIR/android/mydroid/cupcake/out/targe
t/product/generic/obj/lib/crtbegin_dynamic.o -lc
$ file hello
hello: ELF 32-bit LSB executable, ARM, version 1
(SYSV), dynamically linked (uses shared libs), not
stripped
And finally, f you leave out -lc your compilation fails with:
/Users/nirnimesh/NIR/android/mydroid/cupcake/out/targe
t/product/generic/obj/lib/crtbegin_dynamic.o: In
function `_start': bionic/libc/arch-
arm/bionic/crtbegin_dynamic.S:(.text+0x10): undefined
reference to `__libc_init' collect2: ld returned 1 exit
status
So far we've been able to compile C programs using Androids toolchain and
run on the phone.
To summarize, it's the most convenient to use agcc as the compiler so
you don't have to bother.
Posted by Nirnimesh at 1:16 AM
17 comments:
sheiff said...
Wow!
Thousands of thanks!
jervis said...
neiln said...
Jared said...
Awesome man, keep up the updates. I just got my dev phone and have
used a few of your posts already.
Yarx said...
This post has been removed by the author.
Wednesday, April 22, 2009 7:56:00 PM PDT
I published it at http://github.com/tmurakam/droid-wrapper/
StyXman said...
# ./hw
./hw: not found
That's because you have to specify the path to the Android dynamic
linker:
tarek.attia said...
Winston said...
Using the NDK r3 in Android 2.1, I was able to compile with the
following (from the ndk directory):
./build/prebuilt/darwin-x86/arm-eabi-4.2.1/bin/arm-eabi-gcc -o hello
hello.c -Wl,-rpath-link=./build/platforms/android-5/arch-arm/usr/lib/,-
dynamic-linker=/system/bin/linker -L./build/platforms/android-5/arch-
arm/usr/lib/ ./build/platforms/android-5/arch-
arm/usr/lib/crtbegin_dynamic.o -I./build/platforms/android-5/arch-
arm/usr/include -nostdlib -lc
Don't know if it works -- I don't have an Android device, just the SDK
emulator!
Danny said...
This post has been removed by the author.
Tuesday, April 13, 2010 5:44:00 AM PDT
Danny said...
/home/builds/android/prebuilt/linux-x86/toolchain/arm-eabi-
4.4.0/bin/../lib/gcc/arm-eabi/4.4.0/../../../../arm-eabi/bin/ld: cannot find -
lc
collect2: ld returned 1 exit status
Vince said...
Any way around this? With CodeSourcery I was able to compile from
command line very simply:
Thank you.
Lunkwill said...
https://docs.google.com/leaf?
id=0B8R6VSvTZHZWYWI5OTY3NDgtNmFmMS00OTY2LWI1MmMtYT
c0ZmZkZDBmZjk2&hl=en
Vlad said...
This article is old. You now can use the NDK to compile a native C
code file, not only JNI libraries.
Post a Comment
Comment as: Select profile...