1

I am using JNI (Java-Native-Interface) to acess some code that was written in c++. Everything works fine when I run the code from the command line but when I add the code to my Intellij project (class, header-file and dll) it gives the following error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\Robin\Desktop\egdb_example\end.dll: Can't find dependent libraries

My Java Code looks like this :

public class EndGame {

    public static native void openDataBase(int maxPieces, int buffer);

    public static native void test();

    public static native int lookUp(int condition, int BP, int WP, int K, int color);

    public static native void close();

    static {

        System.load("C:\\Users\\Robin\\Desktop\\egdb_example\\end.dll");

    }

    public static void main(String[] args) {

        System.out.println("Kleiner Test");
        openDataBase(8, 2000);
        int value = lookUp(0, 0, 0, 0, 0);
        close();
    }

}

I checked whether the path is actually correct running this piece of code

File test = new File("C:\\Users\\Robin\\Desktop\\egdb_example");

        for (File file : test.listFiles()){
            System.out.println(file.getName());
        }

which produces the outcome:

.git
.gitattributes
.gitignore
egdb.h
egdb.lib
egdb64.dll
egdb64.lib
egdb_example.cpp
egdb_example.vcxproj
egdb_example.vcxproj.filters
end.dll
EndGame.class
EndGame.h
EndGame.java
jni.h
jni_md.h
main.cpp
Readme.pdf
robin.cpp
robin.exe

Would appreciate any help

  • are you sure that the path is correct? – YCF_L Apr 30 '17 at 07:55
  • @YCF_L : double checked that now. See my edit – CheckersGuy Apr 30 '17 at 08:02
  • did u read this http://stackoverflow.com/questions/6092200/how-to-fix-an-unsatisfiedlinkerror-cant-find-dependent-libraries-in-a-jni-pro ? – YCF_L Apr 30 '17 at 08:11
  • Check the [dependencies of your DLL](http://stackoverflow.com/questions/7378959/how-to-check-for-dll-dependency). Make sure they are also in `java.library.path` or in `PATH`. – CrazyCoder Apr 30 '17 at 10:03

1 Answers1

0

Take a look here to see how to setup IntelliJ and CLion to debug code.

http://jnicookbook.owsiak.org/recipe-No-D002/

If you don't use CLion, simply skip that part and take a look solely at IntelliJ configuration.

Oo.oO
  • 11,164
  • 3
  • 21
  • 43