JAVA/JNI - Load native DLL with circular dependency

蓝咒 提交于 2019-12-12 02:56:35

问题


I try to load c++ code in my java project with JNI. I have many several DLL to load, and unfortunately there is a cyclic dependency between two of them : dll A needs dll B which in turns need dll A ! I know it is a bad programming design to have circular dependencies between DLL, but in my project the c++ code is a black box to me.

Is there any way to load DLL with a cyclic dependency ?

Thanks for your help.

jpsi

Details:

My code is quite simple:

System.loadLibrary("myDLLA"); // needs dll B to be loaded!
System.loadLibrary("myDLLB"); // needs dll A to be loaded!
System.loadLibrary("myDLLC"); // needs dll B
// then call my native method implemented in dll C

The java library path is OK and contains the two DLL (it is given as VM argument, I dumped it and checked it at run time too). The cyclic dependency was confirmed by Dependendcy Walker.

The error is :

java.lang.UnsatisfiedLinkError: E:\...\myDLLA.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1928)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1854)
at java.lang.Runtime.loadLibrary0(Runtime.java:845)
at java.lang.System.loadLibrary(System.java:1084)

My project is developed in Eclipse (Helios) as a dynamic web project deployed on a tomcat 6 server.

Please tell me if you need more information.

Again, thanks for any help !!


回答1:


On Windows, the DLL loader will follow the PATH to resolve external references. You can add the directory of myDLLB.dll to PATH globally (through System properties-> advanced), or on command line which launches your Java app (set or xset), or from your Java code.



来源:https://stackoverflow.com/questions/15635945/java-jni-load-native-dll-with-circular-dependency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!