Benoit
Benoit

Reputation: 373

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

Upvotes: 7

Views: 368

Answers (3)

Benoit
Benoit

Reputation: 373

Well, I reinstalled Eclipse and that did it...sigh

The bug was on both Eclipse Luna and Mars Version 4.5.1.

Mars Version 4.5.2 is working fine.

Upvotes: 0

Cibin William
Cibin William

Reputation: 403

When I run the OpenCV program in eclipse ,unsatisfiedLInkError occurs.I solve the error by exporting the library path in eclipse as follows

1.Right click on the project,seleect Debug as->Debug Configurations...

2.Debug Configuration window appears,Select the Environment tab in the top

3.Click the New button on the right side of the window,A New Environment Variable window appears

4.On the Name type LD_LIBRARY_PATH and in the Value type the folder which contain the .dll file(If the .dll is present in the Lib folder inside the project,type Lib in the Value)

Please try and reply.....

Upvotes: 0

Bahramdun Adil
Bahramdun Adil

Reputation: 6089

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);
}

Upvotes: 2

Related Questions