JNI "The specified procedure could not be found" 链接依赖库时

JNI "The specified procedure could not be found" when dependent library is linked

基本工作结构如下:

MainProxy.dll ==> JNIClient.java

使用 JNI,我已成功加载 MainProxy.dll 并能够调用本机函数。以下是所需的结构:

Main.dll ==> MainProxy.dll ==> JNIClient.java

但是当 MainProxy.dll 编译并与另一个 DLL Main.dll 链接时 System.loadLibrary("MainProxy");调用因异常而崩溃

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: MainProxy.dll: The specified procedure could not be found

但是,MainProxy.dll 已成功编译并链接到 Main.lib,并且两个 DLL 都放置在 java 的集合中。

知道导致此问题的原因以及如何解决吗?

以上是 dependencywalker 的截图。 ISPVPLPR.dll 是 Main.dll,LPRPROXY.DLL 是 MainProxy.dll。这两者之间的联系看起来很好。 CreateNativeClass 与其他函数一起从 ISPVPLPR.dll 导出,而在 LPRPROXY.dll.

中仅导入 CreateNativeClass

上面的快照显示了从 LPRProxy.dll

导出的本机函数

我建议您使用 Microsoft 的 Dependency Walker。使用此实用程序真正检查 MainProxy.dll 是否与 Main.dll.

正确链接

如果 Dependency Walker 向您显示问题,请告诉我们您是如何编译和链接的 MainProxy.dll

当 Dependency Walker 向您显示没有问题时,您将不再有 java.lang.UnsatisfiedLinkError

最后,事实证明 OpenCV 预编译库是问题所在。 ISPVPLPR.DLL 正在使用 OpenCV,复制的 DLL 是安装程序附带的默认值,并且是为 WinXP Prof 64 位或 Win2003 64 位编译的。由于 Opencv_Core241.dll 需要 Kernel32.dll 中的 RtlLookupFunctionEntry 和 RtlVirtualUnwind 函数,并且这些函数仅提供给 WinXP 和 Win2003 Kernel32.dll 版本 (MSDN Reference)。

解决方案很简单,只需为 Win7 重新编译 OpenCV2.4.1,并在上帝保佑下成功。