Pregunta

I'm using netbeans 7.4 / jdk 1.7u51

I downloaded the jar for JNA from official site, in version 4.0.0.

I have an internally developped DLL whose interface is in plain C, which loads perfectly well with ctypes in python. This dll is compiled in release with visual 2010, whose runtime are in path.

D:\fl006\Downloads>dir D:\deploy\SpotLight\spotlight-1488\PasanBusLibrary.dll
 Directory of D:\deploy\SpotLight\spotlight-1488

29.01.2014  11:13         1'690'112 PasanBusLibrary.dll

I tried to load it in java with jna:

public interface CLibrary extends Library {
     (...snip...)
    void pasanIpcInitializeLibrary(String xClient, String xBusName, int xTimeout);
    void pasanIpcTerminateLibrary();
}

public static void main(String[] args) {
    NativeLibrary.addSearchPath("PasanBusLibrary","D:\\deploy\\SpotLight\\spotlight-1488");
    CLibrary Bus = (CLibrary) Native.loadLibrary("PasanBusLibrary",CLibrary.class);
(... snip ...)    

This is basically an out of the book standard dll load, from a custom location.

When activating jna debug, I see the following :

run:
Looking in classpath from sun.misc.Launcher$AppClassLoader@714a8f44 for /com/sun/jna/win32-x86-64/jnidispatch.dll
Found library resource at jar:file:/D:/code/perso/TestWrapperBus/jna-4.0.0.jar!/com/sun/jna/win32-x86-64/jnidispatch.dll
Looking for library 'PasanBusLibrary'
Adding paths from jna.library.path: null
Trying D:\deploy\SpotLight\spotlight-1488\PasanBusLibrary.dll
Adding system paths: []
Trying D:\deploy\SpotLight\spotlight-1488\PasanBusLibrary.dll
Looking for lib- prefix
Trying libPasanBusLibrary.dll
Looking in classpath from sun.misc.Launcher$AppClassLoader@714a8f44 for PasanBusLibrary
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'PasanBusLibrary': Native library (win32-x86-64/PasanBusLibrary.dll) not found in resource path ([file:/D:/code/perso/TestWrapperBus/jna-4.0.0.jar, file:/D:/code/perso/TestWrapperBus/jna-platform-4.0.0.jar, file:/D:/code/perso/TestWrapperBus/build/classes/])
    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:271)
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398)
    at com.sun.jna.Library$Handler.<init>(Library.java:147)
    at com.sun.jna.Native.loadLibrary(Native.java:412)
    at com.sun.jna.Native.loadLibrary(Native.java:391)
    at testwrapperbus.TestWrapperBus.main(TestWrapperBus.java:39)

It looks it looks through the location I gave and somehow discards it. I tried different folders and I got same behaviour, there is no obvious file system right issue (dll is RW from all users)

Any clue on what I'm missing, I'm kind of stuck currently...

EDIT

  • if I load "msvcrt" this is working nice to cll printf
  • my dll has some dependencies, all of them hosted in c:\windows\system32 (standard runtime, dynamically linked)
¿Fue útil?

Solución

My dll is a win32 compilation while I use a win64 JDK / JRE. Of course, when dealing with pure java, we don't care but loading native library needs to match.

I tried running from command line on a 32 bits JRE7 and it worked, so I'm pretty sure that installing JDK for win32 in my netbeans or recompiling my dll in 64 bits will solve the issue.

Thanks to this answer : Trying to use DLL from Java (JNA). Unable to load library exception for having put me on the righteous path

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top