在NDK下使用C++編譯程式
這次一樣使用NDK下的範例程式hello-jni示範
1.將hello-jni.c改名為hello-jni.cc,並且在此檔案下加入
class math
{
public:
static int add(int x,int y) {return x+y;}
};
jint
Java_com_example_hellojni_HelloJni_Add( JNIEnv* env,jobject thiz ,
jint x,jint y)
{
return math::add(x,y)
}
2.修改Android.mk
LOCAL_PATH := $(call my-dir)
LOCAL_CPP_EXTENSION := .cc
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.cc
include $(BUILD_SHARED_LIBRARY)
3.編譯
Administrator@mychat-53bb70c5 /cygdrive/d/android-ndk-1.6_r1
$ make APP=hello-jni -B
Android NDK: Building for application 'hello-jni'
SharedLibrary : libhello-jni.so
/cygdrive/d/android-ndk-1.6_r1/build/prebuilt/windows/arm-eabi-4.2.1/bin/../lib/gcc/arm-eabi/4.2.1/.
./../../../arm-eabi/bin/ld: BFD 2.17 assertion fail /cygdrive/c/digit/Android/git/android-ndk/out/ar
m-eabi-4.2.1/toolchain/src/binutils-2.17/bfd/elf32-arm.c:2428
/cygdrive/d/android-ndk-1.6_r1/build/prebuilt/windows/arm-eabi-4.2.1/bin/../lib/gcc/arm-eabi/4.2.1/.
./../../../arm-eabi/bin/ld: BFD 2.17 assertion fail /cygdrive/c/digit/Android/git/android-ndk/out/ar
m-eabi-4.2.1/toolchain/src/binutils-2.17/bfd/elf32-arm.c:2428
/cygdrive/d/android-ndk-1.6_r1/build/prebuilt/windows/arm-eabi-4.2.1/bin/../lib/gcc/arm-eabi/4.2.1/.
./../../../arm-eabi/bin/ld: BFD 2.17 assertion fail /cygdrive/c/digit/Android/git/android-ndk/out/ar
m-eabi-4.2.1/toolchain/src/binutils-2.17/bfd/elf32-arm.c:2428
Install : libhello-jni.so => apps/hello-jni/project/libs/armeabi