Java's own System.loadLibrary library does not work with UnsatisfiedLinkError

I am trying to use a native C ++ library in Java.

When I upload it using

System.loadLibrary(filename); 

I get an error message:

java.lang.UnsatisfiedLinkError: The directory separator should not appear in the library name: C: \ HelloWorld.dll

Any ideas how I can solve this?

+3
source share
4 answers

Just use:

 System.loadLibrary("HelloWorld"); // without c:\ and without ".dll" extension 

Also, make sure HelloWorld.dll is available in the path to your library.

+3
source

For loadLibrary, a file name without path and extension is required.

If you want to use the full path, you can try the System.load () method.

See the java.lang.System API .

+4
source

I used JNA for this ...

JNA is an easy way to call Native functions that the NativeLibrary class provides for this task:

// Java code to call our own function

 dll = NativeLibrary.getInstance(Mydll); Function proxy; proxy = dll.getFunction(Utils.getMethods().get("MyMethodEntryPoint")); byte result[] = new byte[256]; int maxLen = 250; String strVer = ""; Object[] par = new Object[]{result, maxLen}; intRet = (Integer) proxy.invoke(Integer.class, par); if (intRet == 0) { strVer = Utils.byteToString(result); } 

you can find the documentation at http://jna.java.net/

0
source

Surprisingly, you can also use the following:

  final File dll = new File("src/lib/Tester32.dll"); Test32 test32 = (Test32) Native.loadLibrary(dll.getAbsolutePath(), Test32.class); System.out.println(test32.toString() + " - " + test32.GetLastError()); 

It outputs:

 Proxy interface to Native Library <C:\workspace\jna\src\lib\ Tester32.dll@387842048 > - 0 

Javadok says:

Loadlibrary

public static object loadLibrary (row name, Class interfaceClass)

Map the library interface to the shared library data, providing an explicit interface class. If the name is null, try to map to the current process.

If I rename Tester32.dll to the .\src\lib folder for something else, the following exception will occur:

Exception in the thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'C: \ workspace \ jna \ SRC \ Lib \ Tester32.dll': The specified module could not be found.

-1
source

All Articles