JNI : Get java.lang.UnsatisfiedLinkError

JNI : Get java.lang.UnsatisfiedLinkError

本文关键字:lang UnsatisfiedLinkError java Get JNI      更新时间:2023-10-16

这个问题已经被问了好几次,得到了不同的回答。但他们都不适合我。
我已经从我的项目中制作了一个jni dll,用于64x windows 7中使用eclipse和jdk1.7.0_10(64位)。但加载DLL后,我得到java.lang.UnsisfiedLinkError。
我开始根据这个指南创建一个helloworld项目。它说什么我都做。但我已经得到这个错误:

    Exception in thread "main" java.lang.UnsatisfiedLinkError: test.HelloWorld.print()V
    at test.HelloWorld.print(Native Method)
    at test.HelloWorld.main(HelloWorld.java:24)

是的,我已经包含了库路径我已经为x64构建了C项目

代码:

package test;
public class HelloWorld {
    public native void print();  //native method
    static   //static initializer code
    {
        try{
            System.loadLibrary("CLibHelloWorld");
               }
               catch (UnsatisfiedLinkError e) {
                  System.err.println("Native code library failed to load.n" + e);
                  System.exit(1);
                }
    } 
    public static void main(String[] args)
    {
        HelloWorld hw = new HelloWorld();
        hw.print();             //   ==>  i get error on this line
    }
}

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class HelloWorld */
#ifndef _Included_HelloWorld
#define _Included_HelloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     HelloWorld
 * Method:    print
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_HelloWorld_print
  (JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif

#include "HelloWorld.h"
#include "jni.h"
#include  "stdio.h"
JNIEXPORT void JNICALL Java_HelloWorld_print(JNIEnv *env, jobject obj)
{
  printf("Hello worldn");
  return;
}

test.HelloWorld.print的C名称是

Java_test_HelloWorld_print

您缺少_test-是否使用默认包中的类运行javah?

您错过了包名称测试您应该在c 中包含您的包名称