1、Test.java 源文件
public class TestJNI {
static{
System.loadLibrary("goodlucky");
}
public native void set(int value);
public native int get();
public static void main(String[] args) {
TestJNI td=new TestJNI();
td.set(10);
System.out.println(td.get());
}
}
/* DO NOT EDIT THIS FILE - it is machine generated */
#include
/* Header for class TestJNI */
#ifndef _Included_TestJNI
#define _Included_TestJNI
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: TestJNI
* Method: set
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_TestJNI_set
(JNIEnv *, jobject, jint);
/*
* Class: TestJNI
* Method: get
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_TestJNI_get
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
#include
#include "TestJNI.h"
int i=0;
JNIEXPORT void JNICALL Java_TestJNI_set
(JNIEnv * env, jobject obj, jint j)
{
i=j;
}
JNIEXPORT jint JNICALL Java_TestJNI_get
(JNIEnv * env, jobject obj)
{
return i;
}
libgoodlucky.so:TestJNI.o makefile
gcc -Wall -rdynamic -shared -o libgoodlucky.so TestJNI.o
TestJNI.o:TestJNI.c TestJNI.h
gcc -Wall -c TestJNI.c -I./ -I/home/abc/jdk1.7/include -I/home/abc/jdk1.7/include/linux
cl:
rm -rf *.o *.so