以前工作的功能的不满意链接

时间:2013-03-25 20:18:07

标签: java c java-native-interface

我有一个以前工作过的JNI lib, 由于某种原因(我不知道有任何改变)我不能再使用它,因为我收到以下错误:

  

线程“main”中的异常java.lang.UnsatisfiedLinkError:de.ifi.lmu.sommerd.ftsserver.jni.IndexJNI.loadIndex(Ljava / lang / String;)V       at de.ifi.lmu.sommerd.ftsserver.jni.IndexJNI.loadIndex(Native Method)

所以这是我的测试设置:

package de.ifi.lmu.sommerd.ftsserver.jni;

public class IndexJNI {

    static {
        System.load("/home/XXX/workspace/IndexJNI/resources/newLib.so");
        System.out.println("Loading library worked");
        IndexJNI.loadIndex("");
    }


    public static native void loadIndex(String indexName);
}

这里是.h和.c文件的相关部分:

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class de_ifi_lmu_sommerd_ftsserver_jni_IndexJNI */

#ifndef _Included_de_ifi_lmu_sommerd_ftsserver_jni_IndexJNI
#define _Included_de_ifi_lmu_sommerd_ftsserver_jni_IndexJNI
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     de_ifi_lmu_sommerd_ftsserver_jni_IndexJNI
 * Method:    loadIndex
 * Signature: (Ljava/lang/String;)V
 */
JNIEXPORT void JNICALL Java_de_ifi_lmu_sommerd_ftsserver_jni_IndexJNI_loadIndex
  (JNIEnv *, jobject, jstring);

#ifdef __cplusplus
}
#endif
#endif

.c文件

JNIEXPORT void JNICALL Java_de_ifi_lmu_sommerd_ftsserver_jni_IndexJNI_loadIndex
  (JNIEnv * env, jclass jc, jstring indexName) {
...
}

这是我的makefile:

test_gcc_lib: run_queries.o
    g++ -shared -fPIC run_queries.o SSA.a -o newLib.so

1 个答案:

答案 0 :(得分:0)

所以问题是我把调用改为静态, 所以现在签名不再正确了。 我只需要将jobject更改为jclass。