Debugging UnsatisfiedLinkError on Windows

Samuel Audet edited this page Dec 1, 2018 · 3 revisions


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(
    at java.lang.Runtime.loadLibrary0(
    at java.lang.System.loadLibrary(
    at org.bytedeco.javacpp.Loader.loadLibrary(
    at org.bytedeco.javacpp.Loader.load(
    at org.bytedeco.javacpp.Loader.load(
    at org.bytedeco.javacpp.FlyCapture2.<clinit>(
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(
    at org.bytedeco.javacpp.Loader.load(
    at org.bytedeco.javacpp.Loader.load(
    at org.bytedeco.javacpp.FlyCapture2$FC2Version.<clinit>(
    at FlyCapture2Test.PrintBuildInfo(
    at FlyCapture2Test.main(
    ... 6 more
Caused by: java.lang.UnsatisfiedLinkError: /tmp/javacpp3216546462129/ cannot open shared object file: No such file or directory
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(
    at java.lang.ClassLoader.loadLibrary(
    at java.lang.Runtime.load0(
    at java.lang.System.load(
    at org.bytedeco.javacpp.Loader.loadLibrary(
    ... 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 Dependencies.

Using Dependencies Tool

Here is the neat trick:

  1. Download Dependencies 1.8 for x64, extract it somewhere, and

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

    try {
    } catch (UnsatisfiedLinkError e) {
        String path = Loader.cacheResource(<module>.class, "windows-x86_64/jni<module>.dll").getPath();
        new ProcessBuilder("c:/path/to/DependenciesGui.exe", path).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 Dependencies.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.