-
Notifications
You must be signed in to change notification settings - Fork 0
/
dll.txt
53 lines (37 loc) · 868 Bytes
/
dll.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
abc.c
#include<stdio.h>
#include<jni.h>
#include "avcoe.h"
JNIEXPORT jint JNICALL Java_avcoe_sum(JNIEnv *env, jobject thisObj, jint m, jint n)
{
return(m+n);
}
JNIEXPORT jint JNICALL Java_avcoe_sub(JNIEnv *env, jobject thisObj, jint m, jint n)
{
return(m-n);
}
.java
class avcoe
{
static
{
System.loadLibrary("abc");
}
private native int sum(int a,int b);
private native int sub(int a,int b);
public static void main(String args[])
{
avcoe a=new avcoe();
int sum,sub;
sum=a.sum(10,20);
sub=a.sub(30,20);
system.out.println("sum is: "+sum);
system.out.println("sub is: "+sum);
}
}
.h file
cmd
1) javac avcoe.java
2) javac -h jni avcoe.java
3) gcc -fpic -I/home/sl2lab/jdk1.8/include -I/home/sl2lab/jdk1.8/include/linux -o libabc.so -shared abc.c
4) java -Djava.library.path=. avcoe