How to Fix an Unsatisfiedlinkerror (Can't Find Dependent Libraries) in a Jni Project

How to fix an UnsatisfiedLinkError (Can't find dependent libraries) in a JNI project

I'm pretty sure the classpath and the shared library search path have little to do with each other. According to The JNI Book (which admittedly is old), on Windows if you do not use the java.library.path system property, the DLL needs to be in the current working directory or in a directory listed in the Windows PATH environment variable.


Update:

Looks like Oracle has removed the PDF from its website. I've updated the link above to point to an instance of the PDF living at University of Texas - Arlington.

Also, you can also read Oracle's HTML version of the JNI Specification. That lives in the Java 8 section of the Java website and so hopefully will be around for a while.


Update 2:

At least in Java 8 (I haven't checked earlier versions) you can do:

java -XshowSettings:properties -version

to find the shared library search path. Look for the value of the java.library.path property in that output.

JNI: UnsatisfiedLinkError: Can't find dependent libraries

It looks like my problem was the combination of a 64-bit system and java installation and 32-bit C compiler.

By default, the Visual C++ cl compiler generates 32-bit applications, and this caused an error when loaded by 64-bit java. I compiled my application with the Windows SDK 7.1 64-bit compiler, and it ran with no error, as well as removing the warnings in Dependency Walker.

How to solve java.lang.UnsatisfiedLinkError: Can't find dependent libraries without System32?

The best practice for this issue is to load dependent libraries by yourself with calling the library load method:

System.loadLibrary("opencv_1");
System.loadLibrary("opencv_2");
...

After you load dependent libararies now you can safely load your own dll file with the same way:

System.loadLibrary("MyFile");

This should resolve the can't file dependent libraries error.

Another workaround (no the best practice) is to copy dependent dll files (in your case opencv dlls) to System32 folder.

Why this is happening?

I think, when you set java.library.path argument, you are responsible to load dependent libraries of the library, not the OS itself. I'm not sure to be honest.

As mentioned in the How to fix an UnsatisfiedLinkError (Can't find dependent libraries) in a JNI project
, you can check your path by adding -XshowSettings:properties -version argument to the virtual machine.

Win64 - JNI: UnsatisfiedLinkError: Can't find dependent libraries

Check for the following.

1) Make sure that there is no typo in the library name .

incase of linux it should be some thing like

System.load.library("mylib");

then the lib name should be like libmylib.so.

2) You need to add the location of the java library path like

-Djava.library.path="path to your dll location".

3) Make sure that you have compiled your library in the version of Jre you are using i.e ( If you use 64bit Jre you need to compile the dll in 64 bit). Or you can use -d32 or -d64 flags if available in your jre.

4) Make sure that the dll is not in debug mode as it would need the microsoft debug runtime libraries in the machine if so(I have done it quite a few times). If there is any problem with dependencies path walker should help you to identify the dependency problem.

JNI: Can't find dependent libraries

i solved this problem adding my exe file to server folder in jre

Jni + Unsatisfied Link Error + Can't find dependent Libraries

please note that for a dependent library of a jni library rather than being defined on 'java.library.path' its location has to be defined on the PATH environment variable.

hope this helps you out.

cheers,



Related Topics



Leave a reply



Submit