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 working on a Java project that uses the JNI. The JNI calls a custom library that I've written myself, let's say mylib.dll, and that depends on a 3rd party library, libsndfile-1.dll.
When I run my program it crashes with java.lang.UnsatisfiedLinkError: C:...path...\mylib.dll: Can't find dependent libraries.
I've searched this site (and others) and I've tried a number of fixes:
I ran dependency walker. DW gave a couple of warnings -- that two libraries required by libsndfile, MPR.DLL and SHLWAPI.DLL, had "unresolved imports" -- but the DW FAQ said that these warnings could be safely ignored.
I fixed the method names in mylib.dll, as suggested here. The method names had somehow gotten mangled by the compiler, but I added linker flags and the dll method names now match those in my jni header file exactly.
I put all of these DLLs in the same directory -- the same directory as the .jar that calls them -- to ensure that they're on the right PATH.
No dice.
Does anyone have any idea what's going on?
I'm doing my development in Visual Studio 2010 on a MacBook pro (via Parallels). I'm doing my testing in Windows XP on a toshiba laptop.
Answer by QuantumMechanic for 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.
Answer by Steven Peng for How to fix an UnsatisfiedLinkError (Can't find dependent libraries) in a JNI project
I used to have exactly the same problem, and finally it was solved.
I put all the dependent DLLs into the same folder where mylib.dll was stored and make sure the JAVA Compiler could find it (if there is no mylib.dll in the compilation path, there would be an error reporting this during compiling). The important thing you need to notice is you must make sure all the dependent libs are of the same version with mylib.dll, for example if your mylib.dll is release version then you should also put the release version of all its dependent libs there.
Hope this could help others who have encountered the same problem.
Answer by longbkit for How to fix an UnsatisfiedLinkError (Can't find dependent libraries) in a JNI project
I want to inform this interesting case, after tried all the above method, the error is still there. The weird thing is it works on a Windows 7 computer, but on Windows XP it is not. Then I use dependency walker and found on the Windows XP there is no VC++ Runtime as my dll requirement. After installing VC++ Runtime package (here enter link description here) it works like a charm. The thing that disturbed me is it keeps telling Can't find dependent libraries, while intuitively the JNI dependent dll is there, however it finally turns out the JNI dependent dll requires another dependent dl. I hope this helps.
Answer by Rob van Riswick for How to fix an UnsatisfiedLinkError (Can't find dependent libraries) in a JNI project
Did have identical problem with on XP machine when installing javacv and opencv in compination with Eclipse it turned out that I was missing the following files msvcp100.dll and msvcr100.dll once these were installed project compiled and ran OK
Answer by caopeng for How to fix an UnsatisfiedLinkError (Can't find dependent libraries) in a JNI project
Please verify your library path is right or not. Of course, you can use following code to check your library path path: System.out.println(System.getProperty("java.library.path"));
You can appoint the java.library.path when launching a Java application:
java -Djava.library.path=path ...
Answer by Yochai Timmer for How to fix an UnsatisfiedLinkError (Can't find dependent libraries) in a JNI project
You need to load your JNI library.
System.loadLibrary loads the DLL from the JVM path (JDK bin path).
If you want to load an explicit file with a path, use System.load()
See also: Difference between System.load() and System.loadLibrary in Java
Answer by EFalco for How to fix an UnsatisfiedLinkError (Can't find dependent libraries) in a JNI project
If you load a 32 bit version of your dll with a 64 bit JRE you could have this issue. This was my case.
Answer by Pratik Varpe for How to fix an UnsatisfiedLinkError (Can't find dependent libraries) in a JNI project
1 ) Go to ?http://tess4j.sourceforge.net/usage.html? click on -?Visual C++ Redistributable for VS2012 ? donwload it and run (VSU_4\vcredist_x64.exe or VSU_4\vcredist_x84.exe depending upon your system configuration )
2 put your dll files inside lib folder along with your libraries (ex \lib\win32-x86\your dll files).
Answer by estebanuri for How to fix an UnsatisfiedLinkError (Can't find dependent libraries) in a JNI project
I had the same issue, and I tried everything what is posted here to fix it but none worked for me. In my case I'm using Cygwin to compile the dll. It seems that JVM tries to find the JRE DLLs in the virtual Cygwin path. I added the the Cygwin's virtual directory path to JRE's DLLs and it works now. I did something like:
SET PATH="/cygdrive/c/Program Files/Java/jdk1.8.0_45";%PATH%
Answer by bwfrieds for How to fix an UnsatisfiedLinkError (Can't find dependent libraries) in a JNI project
In my situation, I was trying to run a java web service in Tomcat 7 via a connector in Eclipse. The app ran well when I deployed the war file to an instance of Tomcat 7 on my laptop. The app requires a jdbc type 2 driver for "IBM DB2 9.5". For some odd reason the connector in Eclispe could not see or use the paths in the IBM DB2 environment variables, to reach the dll files installed on my laptop as the jcc client. The error message either stated that it failed to find the db2jcct2 dll file or it failed to find the dependent libraries for that dll file. Ultimately, I deleted the connector and rebuilt it. Then it worked properly. I'm adding this solution here as documentation, because I failed to find this specific solution anywhere else.
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
Hello Admin,
ReplyDeleteI'm chipping away at a Java venture that uses the JNI. The JNI considers a custom library that I've thought of myself, suppose mylib.dll, and that relies upon an outsider library, libsndfile-1.dll.
At the point when I run my program it crashes with java.lang.UnsatisfiedLinkError: C:...path...\mylib.dll: Can't discover subordinate libraries.
Regards,
Thanks
RITU