无法理解这个UnsatisfiedLinkError

时间:2015-05-06 04:57:30

标签: java java-native-interface

在为C SDL库创建java包装器时获取此异常:

  

线程“main”中的异常java.lang.UnsatisfiedLinkError:   com.sdl4j.renderer.SDL_Renderer.SDL_CreateRenderer(LCOM / sdl4j /窗/ SDL_Window; II)LCOM / sdl4j /渲染器/ SDL_Renderer;

Java Caller(第一种方法很好,在两个java / c ++方面看起来都是100%相似):

    SDL_Window win = SDL_CreateWindow("Hello World!", 0, 0, 1024, 768, SDL_WindowFlags.SDL_WINDOW_SHOWN);
    SDL_Renderer ren = SDL_CreateRenderer(win, -1, SDL_RendererFlags.SDL_RENDERER_ACCELERATED | SDL_RendererFlags.SDL_RENDERER_PRESENTVSYNC);

Native Java功能:

public static native SDL_Renderer SDL_CreateRenderer(SDL_Window window, int index, int flags);

C标题:

* Class:     com_sdl4j_renderer_SDL_Renderer
* Method:    SDL_CreateRenderer
* Signature:    (Lcom/sdl4j/window/SDL_Window;II)Lcom/sdl4j/renderer/SDL_Renderer;
*/
JNIEXPORT jobject JNICALL     Java_com_sdl4j_renderer_SDL_1Renderer_SDL_1CreateRenderer
(JNIEnv *, jclass, jobject, jint, jint);

C ++实现:

JNIEXPORT jobject JNICALL    Java_com_sdl4j_renderer_SDL_1Renderer_SDL_1CreateRenderer(JNIEnv *env, jclass ,    jobject win, jint index, jint flags) {

cout << "Create renderer: " << endl;
}

看不出为什么它不起作用,请你帮忙。

干杯

1 个答案:

答案 0 :(得分:0)

如果您有重载方法,则需要具有“完整”JNI方法名称 方法名称还应包括参数类型(因此JNI可以区分重载方法)

JNIEXPORT jobject JNICALL     Java_com_sdl4j_renderer_SDL_1Renderer_SDL_1CreateRenderer__Lcom_sdl4j_window_SDL_1Window_2II
(JNIEnv *, jclass, jobject, jint, jint);

从技术上讲,它是相同的方法名称,然后添加2个下划线和参数类型。

_      = /
_1     = _
_2     = ;
_00024 = $