Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse Java OpenCV unsatisfiedLinkError in Test src folder only

When loading the library in my main src folder there is no problem, but in the test src folder I get the error. I can still compile and run all the tests normally and they pass.

Both src folder are in the path and I got opencv as a library. Like I said, everything is working, so I guess it's a problem with Eclipse and the display of the error which should not be displayed? So the main problem is that it's visually a pain.

enter image description here

enter image description here

EDIT2 : I just want to say again that everything is working, the tests are all running, it is simply that they pop as problems (and I don't see the errors of the tests because this unspecifiedlinkerror is before and overshadow them)

Also, it does the same thing on both my Windows and Ubuntu machine.

my path is also correct when I print it out right before the System.loadLibrary as .../opencv-2.4.11/build/lib

EDIT3 : I tried Cibin William answer and put my .dll path but to no avail

enter image description here

like image 790
Benoit Avatar asked Feb 29 '16 16:02

Benoit


1 Answers

You can right on the project and click on Build Path -> Configure Build Path -> then select the Libraries tab and select OpenCV jar file and then expend it and then select on Native Library Location and then click on the Edit and then brows the to the .dll file of OpenCV something like this C:\opencv\build\java\x64 Or C:\opencv\build\java\x86 for 32bit System. And it is that.

Or You can load the library by coding (dynamically)

public static void loadOpenCV_Lib() throws Exception {
    // get the model
    String model = System.getProperty("sun.arch.data.model");
    // the path the .dll lib location
    String libraryPath = "C:/opencv/build/java/x86/";
    // check if system is 64 or 32
    if(model.equals("64")) {
        libraryPath = "C:/opencv/build/java/x64/";
    }
    // set the path
    System.setProperty("java.library.path", libraryPath);
    Field sysPath = ClassLoader.class.getDeclaredField("sys_paths");
    sysPath.setAccessible(true);
    sysPath.set(null, null);
    // load the lib
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
like image 107
Bahramdun Adil Avatar answered Sep 22 '22 06:09

Bahramdun Adil