本文介绍了JNI代码中的UnsatisfiedLinkError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图创建一个简单的JNI项目来获取JNI的挂件,但我一直在遇到这个错误:
线程main中的异常java.lang.UnsatisfiedLinkError:HPAProgram.sayHello()
I don没有太多代码,所以我可以在这里粘贴大部分代码。
我运行以下命令:
javac HPAProgram.java
javah HPAProgram
cc -v -c -fPIC -I / System / Library / Frameworks / JavaVM.framework / Versions / A / Headers / HPAProgram.c ++ -o libHPAProgram.o
libtool -dynamic -lSystem libHPAProgram.o -o libHPAProgram.dylib
LD_LIBRARY_PATH =。
export LD_LIBRARY_PATH
java HPAProgram
HPAProgram.java
public class HPAProgram {
public native void sayHello();
public static void main(String [] args){
System.loadLibrary(HPAProgram);
System.out.println(In java main);
HPAProgram s = new HPAProgram();
s.sayHello();
}
}
HPAProgram.c ++:
/ *
* HPAProgram.c ++
*
*创建日期:2014年2月4日
*作者:zalbhathena
* /
//#include
#include< stdio.h>
#includeHPAProgram.h
JNIEXPORT void JNICALL Java_JniSample_sayHello(JNIEnv * env,jobject obj){
printf(Hello World!\\\
);
}
HPAProgram.h:
/ *不要编辑这个文件 - 它是机器生成的* /
#include< jni.h>
/ * Header for HPAProgram * /
#ifndef _Included_HPAProgram
#define _Included_HPAProgram
#ifdef __cplusplus
externC{
#endif
$ * b $ b *类:HPAProgram
*方法:sayHello
*签名:()V
* /
JNIEXPORT void JNICALL Java_HPAProgram_sayHello
(JNIEnv *,jobject);
#ifdef __cplusplus
}
#endif
#endif
$ b
您有:
和
修复.c文件以同意.h文件。
I'm trying to create a simple JNI project to get the hang of JNI, but I keep running into this error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: HPAProgram.sayHello()
I don't have much code yet, so I can paste most of it here.
I run the following commands:
javac HPAProgram.java
javah HPAProgram
cc -v -c -fPIC -I/System/Library/Frameworks/JavaVM.framework/Versions/A/Headers/ HPAProgram.c++ -o libHPAProgram.o
libtool -dynamic -lSystem libHPAProgram.o -o libHPAProgram.dylib
LD_LIBRARY_PATH=.
export LD_LIBRARY_PATH
java HPAProgram
HPAProgram.java
public class HPAProgram {
public native void sayHello();
public static void main(String[] args) {
System.loadLibrary("HPAProgram");
System.out.println("In java main");
HPAProgram s = new HPAProgram();
s.sayHello();
}
}
HPAProgram.c++:
/*
* HPAProgram.c++
*
* Created on: Feb 4, 2014
* Author: zalbhathena
*/
//#include <jni.h>
#include <stdio.h>
#include "HPAProgram.h"
JNIEXPORT void JNICALL Java_JniSample_sayHello (JNIEnv *env, jobject obj) {
printf("Hello World!\n");
}
HPAProgram.h:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class HPAProgram */
#ifndef _Included_HPAProgram
#define _Included_HPAProgram
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: HPAProgram
* Method: sayHello
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_HPAProgram_sayHello
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
解决方案
It said
You have:
and
Fix the .c file to agree with the .h file.
这篇关于JNI代码中的UnsatisfiedLinkError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!