eclipse NDK生成so,调用自己之前的so,附源码,调用时程序闪退,不知android.mk哪里有错
szivy 2015-01-17 04:57:01 JNI要生成so的源文件:
——————————————————————————————————————————————————————
#include <stdio.h>
#include <jni.h>
#include <dlfcn.h>
#include "com_example_t01_cpp_head.h"
JNIEXPORT jstring JNICALL Java_com_example_t01_cpp_1head_t_1jni(JNIEnv *env,
jobject jo) {
void *handle;
int result=0;
handle = dlopen("test01.so", RTLD_LAZY);//之前已有的so
int (*pmytest)(int);
pmytest=(int(*)(int))dlsym(handle,"main_getroot");
result=pmytest(3);
if (result==3) {
return (env)->NewStringUTF("success");
} else
return (env)->NewStringUTF("fail");
}
_________________________
android.mk,如下:
——————————————————————
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := t01
LOCAL_SRC_FILES := t01.cpp
LOCAL_SHARED_LIBRARIES := test01.so
include $(BUILD_SHARED_LIBRARY)
——————————————————————
test01.so,是之前自己早已有的,代码如下:
#include <stdio.h>
int main_getroot(int a) {
return a;
}
_________________________________
不知为何不能调用test01.so里的函数main_getroot, 不知android.mk是否有误,请会解答,和提供些例子!