JNI: Library is Found on Path, but Method is not (java.lang.UnsatisfiedLinkError)

后端 未结 5 786
南笙
南笙 2021-01-12 15:43

I\'m trying to use JNI and getting java.lang.UnsatisfiedLinkError. Unlike the other million questions asked about this, I have the lib on my path, and have even seen the ex

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-12 16:12

    One possible source of the problem might be that you compiled the code using a C++ compiler, which uses a different [calling convention] than plain C. If thats the case then the solution would be to wrap the code for the method in a extern "C" block like this:

    #ifdef __cplusplus
    extern "C" {
    #endif
    
    JNIEXPORT jint JNICALL Java_com_Tune_add
    ...
    
    #ifdef __cplusplus
    }
    #endif
    

提交回复
热议问题