最简单的JNI编程-实现两个数相加

Java源文件

NativeMethod.java

public class NativeMethod {
//静态代码块,用来加载动态链接库(.dll)
static{
System.loadLibrary("test");
}
//定义本地方法
public native void add();
public static void main(String [] args)
{
NativeMethod nm=new NativeMethod();
nm.add();
}
}


C++头文件(宏)

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class NativeMethod */

#ifndef _Included_NativeMethod
#define _Included_NativeMethod
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class:     NativeMethod
* Method:    add
* Signature: ()V
*/
//在Java中定义的本地方法,把次方法复制到(CPP)源文件中,然后是具体的实现代码啦!
JNIEXPORT void JNICALL Java_NativeMethod_add
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif


你可能感兴趣的:(java,编程,C++,c,jni)