1. Hast Du Lust, bei uns mitzuarbeiten und das AH-Team zu verstärken? Alle Details zu dieser aktuellen Herausforderung findest Du hier.
  1. sven-ola, 15.09.2009 #1

    sven-ola Threadstarter Android-Hilfe.de Mitglied


    didn't find too much info on the web on this, so I've investgated a bit on my own. Here's a sample of how to compile a native executable using the Android-NDK Version 1.5. You need a Linux for that with at least the NDK and the build-essentials installed.

    Note, that there's an oops with setbuf(). Expect others quirks while porting programs. I'll paste the Makefile here so google can index the critial keywors. Sample program in the attached ZIP.

    # Dynamic hello example for Android NDK
    # http://honeypod.blogspot.com/2007/12/dynamically-linked-hello-world-for.html
    NDK = /usr/src/android-ndk-1.5_r1
    NDK_ARCH = $(NDK)/build/platforms/android-1.5/arch-arm
    NDK_COMP = $(NDK)/build/prebuilt/linux-x86/arm-eabi-4.2.1
    ifneq ($(shell uname -m),armv6l)
    # When  not compiling on the phone use cross compiler
    CROSS_COMPILE = $(NDK_COMP)/bin/arm-eabi-
    CC = $(CROSS_COMPILE)gcc
    # bionic setbuf() segfaults, do not use
    CFLAGS +=  -D'setbuf(a,b)='
    CFLAGS += -I$(NDK_ARCH)/usr/include
    %o: %c Makefile
        $(CC) $(CFLAGS) -c $<
    all: hello-gcc hello-ld
    hello-gcc: hello.o fpm.o
        strace -o bla.txt -s 512 -f $(CC) -o $@ \
        -nostartfiles -nodefaultlibs -nostdlib \
            -lc -lm -lgcc -L$(NDK_ARCH)/usr/lib \
        -Wl,-rpath-link -Wl,$(NDK_ARCH)/usr/lib \
        -Wl,--dynamic-linker -Wl,/system/bin/linker \
        $(NDK_ARCH)/usr/lib/crtbegin_dynamic.o \
        $^ \
    hello-ld: hello.o fpm.o
        $(LD) -o $@ \
            -lc -lm -lgcc -L$(NDK_ARCH)/usr/lib \
        -L$(NDK_COMP)/lib/gcc/arm-eabi/4.2.1 \
        -rpath-link $(NDK_ARCH)/usr/lib \
        --dynamic-linker /system/bin/linker \
        $(NDK_ARCH)/usr/lib/crtbegin_dynamic.o \
        $^ \
        rm -f hello-ld hello-gcc
        rm -f *.o
        rm -f *~
    // Sven-Ola


    chrisqn, therealhoudini, enjoy_android und einer weiteren Person gefällt das.
  2. chrisqn, 03.06.2010 #2

    chrisqn Neuer Benutzer

    that MAKE file works great.
    its also possible to use it with eclipse.
    exactly what i was looking for

    thank you very much...
Du betrachtest das Thema "Compling Native C using NDK" im Forum "Android Codeschnipsel",