我是java开发人员,我想使用eclipse和cygwin gcc的本机方法,所以我阅读this link的说明
我跟踪了生成.class文件,.c文件,.h文件.dll文件的所有内容。
我还将hello.dll复制到了c:\ windows \ system32文件夹但该程序无法正常工作请帮帮我
public class HelloJNI
{
static
{
System.loadLibrary("hello");
}
// Declare a native method sayHello() that receives nothing and returns void
private native void sayHello();
// Test Driver
public static void main(String[] args) {
new HelloJNI().sayHello(); // invoke the native method
}
}
使用javah工具生成的.h文件是
#include <jni.h>
/* Header for class HelloJNI */
#ifndef _Included_HelloJNI
#define _Included_HelloJNI
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: HelloJNI
* Method: sayHello
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_HelloJNI_sayHello
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
我使用的make文件是
# Define a variable for classpath
CLASS_PATH = ../bin
# Define a virtual path for .class in the bin directory
vpath %.class $(CLASS_PATH)
all : hello.dll
# $@ matches the target, $< matches the first dependancy
hello.dll : HelloJNI.o
gcc -Wl,--add-stdcall-alias -shared -o $@ $<
# $@ matches the target, $< matches the first dependancy
HelloJNI.o : HelloJNI.c HelloJNI.h
gcc -I"C:\Program Files\Java\jdk1.7.0_51\include" -I"C:\Program Files\Java\jdk1.7.0_51\include\win32" -c $< -o $@
# $* matches the target filename without the extension
HelloJNI.h : HelloJNI.class
javah -classpath $(CLASS_PATH) $*
clean :
rm HelloJNI.h HelloJNI.o hello.dll