0

I'm trying to use:

  1. 32 bit DLL (built with Visual Studio 2015) on a 32 bit JVM running application, on a Windows 7 64 bit machine

  2. 64 bit DLL (built with Visual Studio 2015) on a 64 bit JVM running application, on a Windows 7 64 bit machine

The DLL has a few provided dependencies, but I've set up the 'jna.library.path' to the folder containing all required dependencies so jna should be able to find them. I also added the folder containing the DLL and its dependencies to 'java.library.path' to make sure they are found.

In both cases, unfortunately, I get the

java.lang.UnsatisfiedLinkError: Unable to load library.

Some other points to consider:

  • If I launch my application from the directory containing the libraries, it runs without any problem. Does this indicates a problem with DLL search path for loading?

  • I was previously building the library with Visual Studio 2010, and I was able to load the libraries without a problem. Could this be an issue with the DLL build?

Any ideas on what could be the issue?

I've enabled 'jna.debug_load' and 'jna.debug_load.jna' and the log shows that the correct path is tried but the load still fails (I've checked and rechecked that in both scenarios the correct lib is available at C:\path\to\my\lib[32/64]\xxx.dll). The following log is for the 32 bit DLL loading, but the exact same result happens with the 64 bit DLL.

...snip...
Trying (via loadLibrary) jnidispatch
Looking in classpath from ...[...] for x86/jnidispatch.dll
Found library resource at bundleresource://449.fwk22856250/com/sun/jna/win32-x86/jnidispatch.dll
Trying C:\...snip...\AppData\Local\Temp\jna--892366855\jna1523529206075569309.dll
Found jnidispatch at C:\...snip...\AppData\Local\Temp\jna--892366855\jna1523529206075569309.dll
Looking for library 'xxx'
Adding paths from jna.library.path: C:/path/to/my/lib32
Trying C:\path\to\my\lib32\xxx.dll
Adding system paths: []
Trying C:\path\to\my\lib32\xxx.dll
Looking for lib- prefix
Trying libxxx.dll
Looking in classpath from ...[...]
...
java.lang.UnsatisfiedLinkError: Unable to load library 'xxx': Native library (win32-x86/xxx.dll) not found in resource path...
...snip...
Tom11
  • 2,419
  • 8
  • 30
  • 56
Marcos Bento
  • 2,030
  • 4
  • 22
  • 19
  • *Does this indicates a problem with DLL search path for loading?* Yes. Add that folder to your [`java.library.path`](http://stackoverflow.com/a/1734214/2970947). – Elliott Frisch May 03 '16 at 12:27
  • I tend to agree with you... but I missed that detail in the description, the folder containing the DLL and dependencies as been concatenated to the beginning of both 'jna.library.path' and 'java.library.path'. Still, it doesn't work. Could I be missing something else? – Marcos Bento May 03 '16 at 12:41
  • Try adding that folder to your `PATH`, there might be something going on with WoW32 and the linker (but I'm not certain what). – Elliott Frisch May 03 '16 at 12:50
  • Thanks, Elliott. Adding the folder to PATH actually solved it, but I don't understand why. Shouldn't setting jna.library.path (and java.library.path, eventually) be enough? Is there any way I can do it without having to change the environment to run my application? – Marcos Bento May 03 '16 at 15:27
  • I'm not versed enough in the Window dynamic linker to answer that question; but I've encountered this specific issue before. – Elliott Frisch May 03 '16 at 15:29

1 Answers1

0

java.library.path is derived from PATH on VM startup. java.library.path has no effect on system behavior. It is only used to direct where the JVM makes its initial attempt at loading native libraries.

The system itself uses PATH to inform its search not only for initial loads but also all dependencies. The only control JNA has over loading native libraries is whether to include the target DLL's directory in the search path for dependencies.

technomage
  • 9,861
  • 2
  • 26
  • 40