UnsatisfiedLinkError问题
我正在开发一个使用 JNI 的 Android 应用程序。
命令 javah -jni com.company.tests.MainRenderer
给了我这个输出:
/*
* Class: com_company_tests_MainRenderer
* Method: nativeInit
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_company_tests_MainRenderer_nativeInit
(JNIEnv *, jclass);
/*
* Class: com_company_tests_MainRenderer
* Method: nativeRender
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_company_tests_MainRenderer_nativeRender
(JNIEnv *, jclass);
命令 nm -Ca libRotateJNI.so
给了我这个输出:
00001c25 T Java_com_company_tests_MainRenderer_nativeInit(_JNIEnv*, _jclass*)
00001c29 T Java_com_company_tests_MainRenderer_nativeRender(_JNIEnv*, _jclass*)
这是如何定义这些的功能:
void Java_com_company_tests_MainRenderer_nativeInit( JNIEnv* env, jobject thiz )
{
// ...
}
void Java_com_company_tests_MainRenderer_nativeRender( JNIEnv* env, jobject thiz )
{
// ...
}
并使用以下消息运行它:
WARN/dalvikvm(639): No implementation found for native Lcom/company/tests/MainRenderer;.nativeInit ()V
我确定库已加载。你知道我该如何解决这个问题吗?
I'm developing an Android application that uses JNI.
The command javah -jni com.company.tests.MainRenderer
gave me this output:
/*
* Class: com_company_tests_MainRenderer
* Method: nativeInit
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_company_tests_MainRenderer_nativeInit
(JNIEnv *, jclass);
/*
* Class: com_company_tests_MainRenderer
* Method: nativeRender
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_company_tests_MainRenderer_nativeRender
(JNIEnv *, jclass);
The command nm -Ca libRotateJNI.so
gave me this output:
00001c25 T Java_com_company_tests_MainRenderer_nativeInit(_JNIEnv*, _jclass*)
00001c29 T Java_com_company_tests_MainRenderer_nativeRender(_JNIEnv*, _jclass*)
This is how are defined these functions:
void Java_com_company_tests_MainRenderer_nativeInit( JNIEnv* env, jobject thiz )
{
// ...
}
void Java_com_company_tests_MainRenderer_nativeRender( JNIEnv* env, jobject thiz )
{
// ...
}
And running it with this message:
WARN/dalvikvm(639): No implementation found for native Lcom/company/tests/MainRenderer;.nativeInit ()V
I'm sure library is loaded. Do you know how can I fix this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑您使用 C++ 编译器编译了本机方法,并且没有给它们
extern "C"
链接。您向nm
提供的-C
选项对 C++ 名称进行了分解,但实际上,这些符号的名称与 JVM 正在查找的名称不同,因为代码是经过编译的与 C++ 链接。将您的 C++ 代码包含在extern "C"
块中,这应该可以解决问题。I suspect you compiled your native methods with a C++ compiler, and didn't give them
extern "C"
linkage. The-C
option you're providing tonm
demangles the C++ names, but in reality, the symbols have names different from what the JVM is looking for because the code was compiled with C++ linkage. Enclose your C++ code in anextern "C"
block and this should clear things up.我不知道你的 MainRenderer 是什么以及你正在使用哪个本机库,但我的 c 文件函数总是看起来像这样:
我调用的方法/类是 NDKFooActivity 及其调用本机函数...
I don't know what your MainRenderer is and what native library you are hitting but my c file functions always look something like this:
The method/class I am calling is NDKFooActivity and its invoking a native Function...