java.lang.UnsatisfiedLinkError: Can't find dependent libraries
by Ruben TousThis is a painful exception you will typically see when trying to execute your first real JNI Java program. It means that the system has been able to load the root DLL (the one you specify in System.loadLibrary(...) but not its dependant DLLs. Java is not going to give you more information about which libraries are not reachable. Check this:
- Windows users: Are you setting the PATH variable? THE java.library.path IS NOT USED FOR SOLIVNG DEPENDENCIES IN WINDOWS!
This "particularity" is specially misleading because the java.library.path is used, but only for finding the root DLL. Lots of HelloWorld examples work this way, but
in real situations it always fails because real DLLs have always dependencies. Do this from the command line:
PATH=C:\windows\system32;C:\...\jni_libs;%path% - Linux users: You can set the LD_LIBRARY_PATH variable:
For Bourne Shell, K Shell or Bash, type: export LD_LIBRARY_PATH=/Users/joe/jni_libs:$LD_LIBRARY_PATH
For C Shell, type: setenv LD_LIBRARY_PATH "/.../jni_libs:$LD_LIBRARY_PATH" - Linux users: You can set the java.library.path with the -D option when executing the program.
java -Djava.library.path=".:/.../jni_libs" TestApp
How to know which DLLs are missing?
- Windows users: I recommend you to start including in the PATH the C:\windows\system32 directory
- Download the simple and lovely Dependencywalker from http://www.dependencywalker.com/