Greeting.java
1 2 3 4 5 6 7 | class Greeting{ public static void main(String [] args) { Wrapper wrapper = new Wrapper(); wrapper.print(); // insertNode(&llist, 10); --> llist.insertNode(10); } } |
Wrapper.java
1 2 3 4 5 6 7 8 9 | class Wrapper{ // static block static { System.loadLibrary("greeting"); //Libray Nname libgreeting.so } //native func. declaration public native void print(); } |
root@ubuntu:/working/jni/Greeting# javac Wrapper.java
root@ubuntu:/working/jni/Greeting# javac Greeting.java
Wrapper.class
Greeting.class 파일이 생성
root@ubuntu:/working/jni/Greeting# javah Wrapper Wrapper.h 파일이 생성
root@ubuntu:/working/jni/Greeting# gedit greeting.c
greeting.c
#include <stdio.h>
#include "Wrapper.h"
JNIEXPORT void JNICALL Java_Wrapper_print(JNIEnv *env, jobject obj)
{
printf("Hello, JNI!!!\n");
}
Greeting 실행파일 생성
root@ubuntu:/working/jni/Greeting# cc -o libgreeting.so greeting.c -shared -I /usr/lib/jvm/java-6-sun-1.6.0.26/include/ -I /usr/lib/jvm/java-6-sun-1.6.0.26/include/linux/
jni.h의 헤더파일 위치 인클루드
-I /usr/lib/jvm/java-6-sun-1.6.0.26/include/
jni_md.h의 헤더파일 위치 인클루드
-I /usr/lib/jvm/java-6-sun-1.6.0.26/include/linux/
root@ubuntu:/working/jni/Greeting# export LD_LIBRARY_PATH=.
자바에서는 path by value 라고 쓴다고 한다...
Wrapper.h 를 보면 extern "C" 가 있는데
javah는 C의 함수 사용을 위해 사용하는듯 하다.
'Study > 리눅스' 카테고리의 다른 글
| 프로세서기반 임베디드 리눅스 디바이스 드라이버 (1) (0) | 2014.10.01 |
|---|---|
| 리눅스로 c언어 컴파일하기 Java (2) (0) | 2014.09.19 |
| 리눅스로 c언어 컴파일하기 Linked List (2) (0) | 2014.09.19 |
| 리눅스로 c언어 컴파일하기 Linked List (1) (0) | 2014.09.18 |
| 리눅스로 c언어 컴파일하기 모듈사용하기 (1) (0) | 2014.09.18 |
