Android NDK版本r6b,目的:写一个传统的Makefile来编译一个Android平台的可执行文件和动态库.
文件结构:hello.c和 Makefile
hello.c 内容如下
#include <jni.h>
#include <stdlib.h>
#include <stdio.h>
jint Java_com_miki_ImctestActivity_add( JNIEnv* env,
jobject this,
jint x,
jint y )
{
return (x+y);
}
int main()
{
printf("hello world\r\n");
}
Makefile内容如下
NDKHOME=C:/Android/android-ndk-r6b
PLATFORM=8
GCC=${NDKHOME}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-gcc
CFLAGS := \
-MMD -MP -fpic -ffunction-sections -funwind-tables -fstack-protector \
-D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -Wno-psabi -march=armv5te -mtune=xscale -msoft-float -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 \
-DANDROID -Wa,--noexecstack -O2 -DNDEBUG -g \
-I${NDKHOME}/platforms/android-${PLATFORM}/arch-arm/usr/include
LD=${NDKHOME}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-g++
LDFLAGS=-Wl,-soname,libhello.so --sysroot=${NDKHOME}/platforms/android-${PLATFORM}/arch-arm -Wl,--no-undefined -Wl,-z,noexecstack -lc
hello:hello.o
${LD} ${LDFLAGS} hello.o ${NDKHOME}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a -o $@
libhello.so:hello.o
${LD} -shared ${LDFLAGS} hello.o ${NDKHOME}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a -o $@
hello.o:hello.c
${GCC} ${CFLAGS} -c hello.c -o $@
clean:
rm -f *.o
rm -f *.so
rm -f hello