简体   繁体   中英

Java, OpenCV Exception in thread “main” java.lang.UnsatisfiedLinkError:

I'm trying to use OpenCV 2.4.9 with Eclipse on Windows. I set Eclipse like in this tutorial http://docs.opencv.org/trunk/doc/tutorials/introduction/java_eclipse/java_eclipse.html , but when i clik Run, i got this message:

Exception in thread "main" java.lang.UnsatisfiedLinkError: F:\opencv\build\java\x86\opencv_java249.dll: 
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(Unknown Source)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at pl.forbot.test.Hello.main(Hello.java:11)

Code:

import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;

public class Hello
{
   public static void main( String[] args )
   {
      System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
      Mat mat = Mat.eye( 3, 3, CvType.CV_8UC1 );
      System.out.println( "mat = " + mat.dump() );
   }
}

I found answers only for something like "Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java246 in java.library.path", but it didn't work. I'm new in Java, so please, help me.

How to deal with the UnsatisfiedLinkError

First of all we must verify that the parameter passed in the System.loadLibrary method is correct and that the library actually exists. Notice that the extension of the library is not required. Thus, if your library is named SampleLibrary.dll, you must pass the SampleLibrary value as a parameter.

Moreover, in case the library is already loaded by your application and the application tries to load it again, the UnsatisfiedLinkError will be thrown by the JVM. Also, you must verify that the native library is present either in the java.library.path or in the PATH environment library of your application. If the library still cannot be found, try to provide an absolute path to the System.loadLibrary method.

In order to execute your application, use the -Djava.library.path argument, to explicitly specify the native library. For example, using the terminal (Linux or Mac) or the command prompt (Windows), execute your application by issuing the following command:

java -Djava.library.path= "<path_of_your_application>" –jar <ApplicationJAR.jar>

An example of unsatisfiedLinkError

public class UnsatisfiedLinkErrorExample {

     // Define a method that is defined externally.
     native void CFunction();

     // Load an external library, called "clibrary".
     static {
          System.loadLibrary("clibrary");
     }

     public static void main(String argv[]) {
          UnsatisfiedLinkErrorExample example = new UnsatisfiedLinkErrorExample();
          example.CFunction ();
     }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM