jna
http://www.cnblogs.com/lanxuezaipiao/p/3635556.html
http://www.cnblogs.com/softidea/p/5862484.html
https://yq.aliyun.com/articles/60758
jni
public class JniTest{
public native static int add(int x,int y); //java 代码中声明 native 方法
static {
System.load("/opt/yizhichao/libjia.so"); //以绝对路径加载so文件
}
public static void main(String[] args){
System.out.println(System.getProperty("java.library.path"));
System.out.println(add(1,1));
}
}
iZ28dn2ok1pZ:/opt/yizhichao # javah JniTest
iZ28dn2ok1pZ:/opt/yizhichao # vi JniTest
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class JniTest */
#ifndef _Included_JniTest
#define _Included_JniTest
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: JniTest
* Method: add
* Signature: (II)I
*/
JNIEXPORT jint JNICALL Java_JniTest_add
(JNIEnv *, jclass, jint, jint);
#ifdef __cplusplus
}
#endif
#endif
vi myc2.c
#include <stdio.h>
#include "JniTest.h"
JNIEXPORT jint JNICALL Java_JniTest_add(JNIEnv *env, jclass jc, jint x, jint y){
return x+y; //简单的加法
}
gcc -Wall -fPIC -O2 -c -I /opt/JDK/include -I /opt/JDK/include/linux -o libjia.o myc2.c
gcc -shared -o libjia.so libjia.o
export LD_LIBRARY_PATH=.
iZ28dn2ok1pZ:/opt/yizhichao # javac JniTest.java
iZ28dn2ok1pZ:/opt/yizhichao # java JniTest
.:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2