1

I am trying to import a .dll in java (java 11) with JNA. I compiled the dll's myself (using mingw64), verified that they are 64 bit and made sure all dependencies (i.e. linked dlls) are available in the same path. However, I still get the following error message. What am I doing wrong?

java.lang.UnsatisfiedLinkError: Unable to load library 'libClp-0':
The specified module could not be found.

The specified module could not be found.

The specified module could not be found.

Native library (win32-x86-64/libClp-0.dll) not found in resource path

The dll's regard COIN-OR's CLP solver. As mentioned, I have compiled them myself using MSYS2 (64 bit) and COIN-OR's coinbrewscript. I subsequently used dependencies to verify that all dll dependencies are met (had to copy some dll's from "C:\msys64\mingw64\bin" as they were referenced as well).

My folder structure, in Eclipse, is the following:

src 
 |  |clpsolver.model
 |  |     |CLPDLLInterface.java
lib
    | x64
           | all dlls

In the CLPDLLInterface.java file, I use JNA as:

  String libSubDir = "lib" + File.separator + "x64";
  String dir = JNAPathHelper.addPluginRootToNativePath(CLPDLLInterface.class, libSubDir);
  if (dir == null) {
    System.loadLibrary("libClp-0.dll");
  }
  Native.register("libClp-0.dll");
}

libClp-0.dll depends on other dll's, and so on. I tried to load the dll that has no other dependencies than system32 dlls suing dependencies, though even that one won't load. What should I change to make this work?

Microsoft c++ redistributable is installed, and all dlls are executable, see this stackoverflow question

simon
  • 77
  • 7
  • Make sure all the DLLs, your own and its dependencies, are is the same folder, then make sure that folder is in the `java.library.path` system property, or in the `PATH`, which is the default value for the `java.library.path` system property. – Andreas Oct 12 '20 at 09:56
  • If i'm right, this is what the JNAPathHelper.addPluginRootToNativePath() function does. – simon Oct 12 '20 at 10:06
  • Does this help? https://stackoverflow.com/questions/47031176/java-loadlibrary-unresolved-dependency-but-dependent-dll-is-in-same-directory/47075532#47075532 – user2543253 Oct 12 '20 at 11:38
  • Also, I don't know what `JNAPathHelper` does, but I assume it adds the specified directory to those that are searched by JNA itself. `System.loadLibrary()` doesn't know about those paths, only JNA does. You might get a different result using `Native.load()` or `NativeLibrary.getInstance()` – user2543253 Oct 12 '20 at 13:05
  • You shouldn't be changing the path. That's not the right solution. The right solution is to use side by side application manifests. That can be a bit of a fiddle. But it does make life a lot cleaner and more secure. If you can't do that, then you can load each of the dependencies before any dependent DLLs. So longer as when each DLL loads any dependent DLLs are already loaded, you will have no problems. Yet another approach is to use `SetDllDirectory` or `AddDllDirectory`. – David Heffernan Oct 12 '20 at 14:05
  • Generally if the DLL is not in the current directory nor in a path normally traced by the system (e.g. %PATH%), you need to either edit %PATH% or manually invoke `System.load()` using the full path to the DLL. This applies to all DLL dependencies. – technomage Oct 28 '20 at 15:40

0 Answers0