使用 Dependency Walker 验证 DLL 中的 C 函数
我是 dependency walker 的新手,我正在尝试确定我的 dll 是否包含我试图通过 JNI 从 Java 调用的 C 函数。当我在 Dependency Walker 中选择应包含 C 函数的 dll 时,我获得了导入和导出函数。导入列表具有 setLogLevel 函数,但入口点未绑定(与此列表中的所有函数一样),并显示带有 c 的绿色框。导出列表具有 setLogLevel 函数,并以 0x00003C25 作为入口点。当我尝试从 JAVA/JNI 调用 setLogLevel 时,我得到以下信息。我不确定导入/导出是否正确,有人可以确认吗?
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.test.jni.SampleJNI.setLogLevel(I)V
at com.test.jni.SampleJNI.setLogLevel(Native Method)
at com.test.jni.Sample.setLogLevel(Unknown Source)
at com.test.jni.Example.setLogLevel(Unknown Source)
at com.test.jni.Example.main(Unknown Source)
I'm new to dependency walker and I'm trying to determine if my dll contains a C function that I'm trying to call from Java via JNI. When I select the dll that should contain the C function in Dependency Walker, I get the import and export functions. The import list has the setLogLevel function but the entry point is not bound (as is for all functions in this list) and shows up with a green box with a c. The export list as has a setLogLevel function and has 0x00003C25 as the entry point. When I try to call the setLogLevel from JAVA/JNI I get the below. I'm not sure if the import/exports are right, can anyone confirm?
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.test.jni.SampleJNI.setLogLevel(I)V
at com.test.jni.SampleJNI.setLogLevel(Native Method)
at com.test.jni.Sample.setLogLevel(Unknown Source)
at com.test.jni.Example.setLogLevel(Unknown Source)
at com.test.jni.Example.main(Unknown Source)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的 C 函数命名不正确。该名称必须以
Java
为前缀,并包含包名和类名。在您的情况下,它应该是Java_com_test_jni_SampleJNI_setLogLevel
。Your C function is named incorrectly. The name must be prefixed with
Java
and contain the package and class name. In your case, it should beJava_com_test_jni_SampleJNI_setLogLevel
.我在 Makefile 中省略了包含 CFLAGS(编译)中包含 jdk 的 jni.h 和 jni_md.h 头文件的 java 目录。将它们添加到 Makefile 后,我就能够通过 JNI 方法调用从 java 到 c 进行通信。
I had omitted the java directories that have the jdk's jni.h and jni_md.h header files from the CFLAGS (compile) include in the Makefile. Once I added those to the Makefile I was able to communicate from java to c via JNI method calls.