I'm working on a Java project on Eclipse, which uses C++ OpenCV libraries via JNI. Some image processing algorithms are implemented with OpenCV on the native side, and I wish to use them from java using JNI.
I have built a C++ DLL project to link to Java, which resulted in a MyLibrary.dll
file. I compiled OpenCV with GCC 6.3 compiler and I compiled the C++ code with the same GCC 6.3 compiler on Eclipse CDT (along with MinGW Linker). I also checked if there are any dependency issues using Dependency Walker. I had no errors thus far.
Afterwards, I tried to load the library from Java code as follows:
System.loadLibrary("MyLibrary")
I have set the path with -Djava.library.path=path\to\MyLibrary
, and and made sure that JVM knows the address of the native libraries. I also added the required OpenCV libraries next to MyLibrary.dll
.
However I get the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: MyLibrary.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
...
Then the problem goes away, when I move the dependent OpenCV libraries into the System32
folder.
My question is; how can I solve this issue without moving the required DLL files into the System32
folder?