java.lang.UnsatisfiedLinkError - JNI

前端 未结 3 1963
太阳男子
太阳男子 2021-01-21 18:43

I keep getting a java.lang.UnsatisfiedLinkError error every time I run my program. I have a native, a wrapper, and the program to call the native through the wrapper.<

相关标签:
3条回答
  • 2021-01-21 19:09

    I think the problem is that your JNI signature doesn't match. That is:

    JNIEXPORT void JNICALL native_MessageBox(string text, string title);
    

    should be something like:

    JNIEXPORT void JNICALL java_com_example_Wrapper_native_MessageBox(string text, string title);
    

    where, java_com_example should be replaced with your package name (. to be replace with _ in package name).

    OR

    I would suggest you to generate your native function signature and declaration using javah -jni option available in java.

    0 讨论(0)
  • 2021-01-21 19:23

    If you test with

    nativeFile = new File(filename + ".dll");
        if (!nativeFile.exists())
            System.exit(1);
    

    you should use it !!

    System.load(nativeFile);
    

    There are two different ways to load a native library into a running Java program:

    • System.loadLibrary(String) and System.load(String).

    • The System.loadLibrary method allows us to load a library from the "default" path.

      System.loadLibrary("HelloWorld");

    • System.load allows us to load a library from anywhere via its absolute path.
      System.load("c:/path/to/dll/HelloWorld.dll");

    0 讨论(0)
  • 2021-01-21 19:27

    Another thing which could be reason for that error is missing header file when you compile our cpp library. Make sure that you included header in your cpp file.

    0 讨论(0)
提交回复
热议问题