Jetzt kostenlos registrieren. Mitglieder surfen ohne Werbung auf Android-Hilfe.de!
Zurück   Android-Hilfe.de > Android Developer > Android Codeschnipsel

Compling Native C using NDK

Das Thema "Compling Native C using NDK" befindet sich unter Android Codeschnipsel auf Android-Hilfe.de.


Antwort

 

Themen-Optionen Ansicht
Alt 15.09.2009, 10:38   #1 (permalink)
Android-Hilfe.de Mitglied

Registriert seit: 31.07.2009
Beiträge: 75
Abgegebene Danke: 1
Erhielt 25 Danke für 13 Beiträge
Standard Compling Native C using NDK

Hey,

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.

Code:
# 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-
endif

CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld

# bionic setbuf() segfaults, do not use
CFLAGS +=  -D'setbuf(a,b)='
CFLAGS +=  -DUSE_FPM
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 \
    $^ \
    $(NDK_ARCH)/usr/lib/crtend_android.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 \
    $^ \
    $(NDK_ARCH)/usr/lib/crtend_android.o

clean:
    rm -f hello-ld hello-gcc
    rm -f *.o
    rm -f *~
// Sven-Ola
Angehängte Dateien
Dateityp: zip android-dynamic.zip (12,3 KB, 183x aufgerufen)
sven-ola ist offline   Mit Zitat antworten
Folgende Benutzer bedanken sich bei sven-ola für diesen Beitrag:
chrisqn (03.06.2010), Eclipse (17.09.2009), enjoy_android (11.10.2009), therealhoudini (01.02.2010)
Alt 03.06.2010, 15:41   #2 (permalink)
Neuer Benutzer

Registriert seit: 03.06.2010
Beiträge: 2
Abgegebene Danke: 1
Erhielt 0 Danke für 0 Beiträge
Standard AW: Compling Native C using NDK

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

thank you very much...
chris
chrisqn ist offline   Mit Zitat antworten
Antwort

Stichworte
-

Themen-Optionen
Ansicht


Ähnliche Themen

Thema Autor Forum Antworten Letzter Beitrag
Native Anwendungen im Emulator testen Trass3r Android App Entwicklung 0 02.09.2009 15:06
ndk Apps Archer Sonstige Apps & Widgets 2 18.08.2009 20:34
Android NDK erschienen eagle99 Android App Entwicklung 3 26.06.2009 17:09




Du liest gerade: "Compling Native C using NDK" unter "Android Codeschnipsel" auf Android-Hilfe.de.


Powered by vBulletin®
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO
© Android-Hilfe.de 2012 - All rights reserved.