Android NDK动态库的调用
2010-09-16 23:50:00 来源:WEB开发网{
//getinformation(); ??thr .so file will load to the sdcard with the folder data/data/com.example.test/lib/
void* filehandle = dlopen("/data/data/com.example.test/lib/libtutorial.so", RTLD_LAZY );
int ll = -1;
if(filehandle)
{
LOGI("open so success!");
int( * getinformation ) ();
getinformation = dlsym(filehandle, "getinformation");
if( getinformation )
{
LOGI("call function getinformation OK!");
ll = getinformation();
}
else
{
ll = -3;
LOGE("call function getinformation! ERROR!");
}
LOGI("return value=%d",ll);
dlclose(filehandle);
filehandle=0;
}
else
{
ll = -2;
LOGE("open so ERROR!");
}
return ll;
}
tutorial01.c
#include
#include "tutorial02.h"
int getinformation()
{
int c = getinformation2(191,81);
return c;
}
tutorial02.c
#include
#include "tutorial02.h"
int getinformation2(int i,int j)
{
return (i+j);
}
tutorial02.h
int getinformation2(int,int);
C: 编译:
进入工程目录,执行 $NDK/ndk-build
输出结果:
$NDK/ndk-build
/cygdrive/e/cygwin/android-ndk-r4
Compile thumb : test <= /cygdrive/e/cygwin/android-ndk-r4/samples/testappso/jni/test01.c
SharedLibrary : libtest.so
Install : libtest.so =>
更多精彩
赞助商链接