【发布时间】:2014-05-14 06:29:18
【问题描述】:
我还没有找到解决我的问题的方法,从昨天开始就一直在寻找。 我正在使用带有 CDT 和 MinGW 的 Windows 7 和 Eclipse。
这是我的 JAVA 类:
package pl.asg.front;
public class ASGFrontMain {
static
{
System.loadLibrary("libASG");
}
public native void sayHello();
public static void main(String[] args) {
System.out.println("Hello from JAVA!");
new ASGFrontMain().sayHello();
}
}
这是我的 jni javah 生成的头文件:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class pl_asg_front_ASGFrontMain */
#ifndef _Included_pl_asg_front_ASGFrontMain
#define _Included_pl_asg_front_ASGFrontMain
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: pl_asg_front_ASGFrontMain
* Method: sayHello
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_pl_asg_front_ASGFrontMain_sayHello
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
使用 eclipse 外部工具的东西: 地点: C:\Program Files (x86)\Java\jdk1.7.0_51\bin\javah.exe 工作目录: ${workspace_loc:/ASG/bin} 论据: -d ${workspace_loc:/ASG/asg_jni} ${java_type_name}
这是我的 .cpp 实现:
/*
* pl_asg_front_ASGFrontMain.c
*
* Created on: 2 kwi 2014
* Author: karol
*/
#include "pl_asg_front_ASGFrontMain.h"
JNIEXPORT void JNICALL Java_pl_asg_front_ASGFrontMain_sayHello
(JNIEnv *env, jobject obj)
{
}
我得到了这个输出:
Exception in thread "main" java.lang.UnsatisfiedLinkError: pl.asg.front.ASGFrontMain.sayHello()V
at pl.asg.front.ASGFrontMain.sayHello(Native Method)
Hello from JAVA!
at pl.asg.front.ASGFrontMain.main(ASGFrontMain.java:13)
有什么解决办法吗?提前致谢。
【问题讨论】:
-
如何构建
libASG?它需要是 DLL,而不是 .lib。
标签: java c++ eclipse java-native-interface