java - JNI : Get java. lang.UnsatisfiedLinkError 错误

标签 java c++ c eclipse java-native-interface

这个问题已经被问过好几次,并且有不同的接受答案。但它们都不适合我。
我从我的项目中制作了一个 jni dll,用于 64x windows 7,使用 eclipse 和 jdk1.7.0_10(64 位)。但是在加载我的 DLL 之后,我得到了 java.lang.UnsatisfiedLinkError。
我开始基于这个创建一个 helloworld 项目 guide .我做了它说的一切。但我已经收到此错误:

    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 项目是的,我正在使用 64 位 jvm。

代码:

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 world\n");
  return;
}

最佳答案

test.HelloWorld.print 的 C 名称是

Java_test_HelloWorld_print

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

关于java - JNI : Get java. lang.UnsatisfiedLinkError 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25618315/

相关文章:

java - Joda 时间 - 解析字符串抛出 java.lang.IllegalArgumentException

java - 使用列表和复选框的 Spring MVC 数据绑定(bind)

javascript - 无法使用带有 PageFactory 的 Selenium Java 选择下拉元素

c++ - 将共享库文件放入C++项目中

c - C中访问并运行/usr/bin程序

java - ServiceTracker、服务引用和服务引用之间的区别

c++ - 为什么在动态分配的数组上调用 delete 会导致一个崩溃而不是另一个?

c++ - 如何在 C++ 中正确返回数组(类成员)?

c - malloc和指针代码演示

c++ - 源码分析工具?