1

I have a problem when I try load a DLL like this:

String a = "C:\\Users\\ElteGps 022\\Documents\\NetBeansProjects\\JavaApplication1\\src\\lib\\EQ2008_Dll.dll";
        String strDllFileName = m_strUserPath + "\\res\\EQ2008_Dll.dll";
        String strEQ2008_Dll_Set_Path = m_strUserPath + "\\res\\EQ2008_Dll_Set.ini";
        m_DllLibrary = (DllLibrary) Native.loadLibrary(a,DllLibrary.class);

I see this:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'C:\Users\ElteGps 022\Documents\NetBeansProjects\JavaApplication1\src\lib\EQ2008_Dll.dll': Nie mo¿na odnaleæ okrelonego modu³
    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:163)
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:236)
    at com.sun.jna.Library$Handler.<init>(Library.java:140)
    at com.sun.jna.Native.loadLibrary(Native.java:379)
    at com.sun.jna.Native.loadLibrary(Native.java:364)
    at javaapplication1.Fun.main(Fun.java:280)

I read and I did this:

Community
  • 1
  • 1
Krzysztof Pokrywka
  • 1,356
  • 4
  • 27
  • 50

1 Answers1

4

From the JNA javadoc

Library Search Paths A search for a given library will scan the following locations:
  1. jna.library.path User-customizable path
  2. jna.platform.library.path Platform-specific paths
  3. On OSX, ~/Library/Frameworks, /Library/Frameworks, and /System/Library/Frameworks will be searched for a framework with a name corresponding to that requested. Absolute paths to frameworks are also accepted, either ending at the framework name (sans ".framework") or the full path to the framework shared library (e.g. CoreServices.framework/CoreServices).
  4. Context class loader classpath. Deployed native libraries may be installed on the classpath under ${os-prefix}/LIBRARY_FILENAME, where ${os-prefix} is the OS/Arch prefix returned by Platform.getNativeLibraryResourcePrefix(). If bundled in a jar file, the resource will be extracted to jna.tmpdir for loading, and later removed (but only if jna.nounpack is false or not set).
You may set the system property jna.debug_load=true to make JNA print the steps of its library search to the console.

Native.loadLibrary doesn't work with a full path, try instead System.load If you can't use that you could also specify the directory of the dll before the loading by setting the enviroment variable of java like this

System.setProperty("jna.library.path", "C:\\Users\\ElteGps 022\\Documents\\NetBeansProjects\\JavaApplication1\\src\\lib");

But this is higly not recommended since it will works only on your computer

Emax
  • 1,343
  • 2
  • 19
  • 30
  • When I do this : System.setProperty("jna.library.path", "C:\\Users\\ElteGps 022\\Documents\\NetBeansProjects\\JavaApplication1\\src\\lib"); I see this same result – Krzysztof Pokrywka Oct 11 '16 at 09:41
  • And when I use System.load I see this : Can't load IA 32-bit .dll on a AMD 64-bit platform – Krzysztof Pokrywka Oct 11 '16 at 09:44
  • @KrzysztofPokrywka you are loading a 32bit library on a 64bit jvm that's the problem, try to load the same library compiled for 64bit – Emax Oct 11 '16 at 10:55
  • I load o 32 bit i download a java 32 bit ant it work but when I use a System.load I can't create object m_DllLibrary = System.load I don't know how I can do it – Krzysztof Pokrywka Oct 11 '16 at 10:57
  • @KrzysztofPokrywka Retry to use Native.loadLibrary with the full path and tell me what happens – Emax Oct 11 '16 at 11:01
  • When I use a Native.load Libary I have this : Exception in thread "main" java.lang.UnsatisfiedLinkError: Directory separator should not appear in library name: C:\Users\ElteGps 022\workspace22\EQ2008_Dll_Java\res\EQ6003_Dll.dll at java.lang.Runtime.loadLibrary0(Unknown Source) at java.lang.System.loadLibrary(Unknown Source) at com.eq2008.Fun.main(Fun.java:278) – Krzysztof Pokrywka Oct 11 '16 at 11:12
  • @KrzysztofPokrywka try to move the dll in the windows folder and test with Native.loadLibrary only with the name of the dll – Emax Oct 11 '16 at 11:16
  • I've noticed that when I use windows, OpenGL32.dll is automatically loaded, probably off the classpath. How does java go about adding native libraries to the classpath, and is there some list of which ones are on the classpath? – pdid Sep 12 '17 at 21:38