简体   繁体   中英

JNI : Get java.lang.UnsatisfiedLinkError

This has been asked several time and have different accepted answers. but none of them worked for me.
I have made a jni dll from my project to use in 64x windows 7 working with eclipse and jdk1.7.0_10 (64bit). but after loading my DLL i get java.lang.UnsatisfiedLinkError.
I started to create a helloworld project based on this guide . and i do everything it said. but i already get this error:

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

Yes I have included the library path and yes i have build the C project for x64 and yes i'm using 64bit jvm.

Codes:

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
    }
}

and

/* 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

and

#include "HelloWorld.h"
#include "jni.h"
#include  "stdio.h"

JNIEXPORT void JNICALL Java_HelloWorld_print(JNIEnv *env, jobject obj)
{
  printf("Hello world\n");
  return;
}

The C name for test.HelloWorld.print is

Java_test_HelloWorld_print

you are missing the _test - did you run javah with the class in the default package?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM