Java.lang.UnsatisfiedLinkError: method inside dll not available

I am trying to access a function available inside a dll file. But it gives an exception like "Exception in the stream" main "java.lang.UnsatisfiedLinkError: * .jniGetAudioInputLevel () D". The dll file is loading, but when I try to access the methods, they give an error message.

According to my information: -

  • This exception only occurs if the .dll is missing from the class path or the DLL is not present in the jar file. File
  • .dll is created only if all the code is launched with an error.
  • I saw methods in the dll using tools such as: Anywhere PE Viewer, PE Explorer, etc. Both of them show the methods available in the DLL file.

How can this be done with the ability to access a function using any other idea?

+4
source share
3 answers

UnsatisfiedLinkError is also raised if a native instance of a method declared by native cannot be found. This can happen if the native code was not named with the full name of the Java package, separated by "_".

For instance,

package com.mycompany.stuff; public native void doSomething(); 

It is required that the built-in library (DLL, so, * SRVPGM, etc. depending on your system) be found and loaded with System.loadLibrary (), which contains and exports a function named

 com_mycompany_stuff_doSomething 

If you are sure that the native library is loading, I assume that the function is incorrectly named or not exported.

+6
source

I agree with Software Monkey , but I have one very important addition related to the function name. The function name in the source library must begin with ' _Java_ '. In your case, it should be:

 _Java_com_mycompany_stuff_doSomething 

I found this by accident and spent two days figuring out why the JVM cannot find the function in the DLL, if any. In my case, javah generates a header file with the name of the function without an underscore before "Java_". So I had to update it manually to make it work.

I wonder why he didn’t mention the underscore prefix in the “Guide and Specification for Java Programmers”, “Java Native Interface 6.0 Specification,” which comes with Java 6 documentation (I worked with jdk 1.6.0_30, but the JDK version should not be problem) and some other resources.

+4
source

Usually we get this exception when the JVM cannot find the .dll file.

0
source

Source: https://habr.com/ru/post/1301081/


All Articles