Skip to content

Debugging UnsatisfiedLinkError on Windows

Samuel Audet edited this page Jul 27, 2016 · 5 revisions

Introduction

On most platforms, including Android, Linux, and Mac OS X, when the operating system cannot load a library, it provides useful information to resolve easily the loading issue. For example, if we try to use the JavaCPP Presets for FlyCapture on Linux without having actually installed the library for FlyCapture, we get thrown the following exception:

java.lang.UnsatisfiedLinkError: no jniFlyCapture2 in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1864)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1122)
    at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:636)
    at org.bytedeco.javacpp.Loader.load(Loader.java:474)
    at org.bytedeco.javacpp.Loader.load(Loader.java:411)
    at org.bytedeco.javacpp.FlyCapture2.<clinit>(FlyCapture2.java:10)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at org.bytedeco.javacpp.Loader.load(Loader.java:446)
    at org.bytedeco.javacpp.Loader.load(Loader.java:411)
    at org.bytedeco.javacpp.FlyCapture2$FC2Version.<clinit>(FlyCapture2.java:709)
    at FlyCapture2Test.PrintBuildInfo(FlyCapture2Test.java:28)
    at FlyCapture2Test.main(FlyCapture2Test.java:135)
    ... 6 more
Caused by: java.lang.UnsatisfiedLinkError: /tmp/javacpp3216546462129/libjniFlyCapture2.so: libflycapture.so.2: cannot open shared object file: No such file or directory
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1938)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1821)
    at java.lang.Runtime.load0(Runtime.java:809)
    at java.lang.System.load(System.java:1086)
    at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:619)
    ... 16 more

Unfortunately, Windows is not as cooperative: The case of the DLL that refuses to load

Nevertheless, there is a way to obtain the same kind of information almost as easily on Windows using Dependency Walker with the following hack.

Using Dependency Walker

Here is the neat trick:

  1. Download Dependency Walker 2.2 for x64 and extract it somewhere

  2. Call the following at the beginning of the main() method or during initialization somewhere:

    try {
        Loader.load(<module>.class);
    } catch (UnsatisfiedLinkError e) {
        new ProcessBuilder("c:/path/to/depends.exe", Loader.getTempDir() + "/jni<module>.dll").start().waitFor();
    }

∗ Replace <module> with the JavaCPP Presets module that is having problems loading, for example, opencv_core.


After which please feel free to file an issue as appropriate along with the information you obtained from Dependency Walker.