I'm using the following code to load a dll in JNA (irrelevant code is left out):
public class JNAMain {
public interface PointShapeBuffer extends Library { ... }
public static void main(String[] args){
System.setProperty("jna.library.path", "c:\\jnadll");
System.setProperty("java.library.path", "c:\\jnadll");
PointShapeBuffer jna = (PointShapeBuffer) Native.loadLibrary("FileGDBAPI", PointShapeBuffer.class);
}
}
And I get the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'FileGDBAPI': The specified module could not be found.
I've also tried setting the VM args. Any suggestions would be great.
Edit: For reference, I am using a publicly available library found here (registration is required).
You might want to download the latest version with jna.jar and platform.jar and just include those. No need to set the path then.
Change your:
Native.loadLibrary("FileGDBAPI", PointShapeBuffer.class);
to:
Native.loadLibrary("C:\\jnadll\\FileGDBAPI.dll", PointShapeBuffer.class);
If you dive into the jna source code enough you will find a nice little hook in the NativeLibrary class:
/** Use standard library search paths to find the library. */
private static String findLibraryPath(String libName, List searchPath) {
//
// If a full path to the library was specified, don't search for it
//
if (new File(libName).isAbsolute()) {
return libName;
}
...
So it will catch if you just passed an absolute path and not even use the searchPath. This was why you dont have to worry about jna.library.lib.
In my experience you usally see this error when calling 32bit native dlls from a 64bit jvm on 64bit Win7. Win7 works differently for 64bit and 32bit applications.
On 64bit Win7 you can call functions in native 32bit dll's, but you need to use a 32bit JVM.
The reason for this is 32bit dll's are incompatible with 64bit applications, and 64bit Win7 uses a 32bit emulator to run 32bit applications. Although Windows Libraries might be called named xxxx32.dll (e.g. user32.dll) the libraries in the System32 folder on a 64bit Win7 are 64bit libraries, not 32bit, and the libraries in SysWOW64 are 32bit libraries, confusing right?!?
You can also place the library in the 32bit system folder (SysWOW64) and make the JNI call from within a 32bit JVM.
Check out the following link for a full explanantion as how 64bit Win7 handles libraries;
http://www.samlogic.net/articles/32-64-bit-windows-folder-x86-syswow64.htm
And if you really want to help yourself get to sleep, trying starting on this ;)
http://msdn.microsoft.com/en-us/windows/hardware/gg463051.aspx
You need to specify the folder containing your DLL, not the DLL's actual path.
e.g. for baz.dll
at c:\foo\bar\baz.dll
, the path should be set to c:\\foo\\bar
. (note in Java if you're using backspaces you'll have to escape them with backslashes)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With