[Jamvm-general] Error when using JNI
Brought to you by:
rlougher
From: ZNTU <Z0...@nt...> - 2008-12-10 08:06:28
|
Hi, Currently I've tried to do some programing with JNI but when I run java programs there is and error as it cannot find native library... may I have any suggestion that what should I do about it? Here is what I have done so far. 1. create java source code and store in /home/user/jni ------ class HelloWorld { private native void print(); public static void main(String[] args) { new HelloWorld().print(); } static { System.loadLibrary("HelloWorld"); } } ------ 2. compile java javac HelloWorld.java 3. create header file javah -classpath . -d . -jni HelloWorld ------------------ /* DO NOT EDIT THIS FILE - it is machine generated */ #include <jni.h> /* Header for class HelloWorld */ #ifndef _Included_HelloWorld #define _Included_HelloWorld #ifdef __cplusplus extern "C" { #endif /* * Class: HelloWorld * Method: print * Signature: ()V */ JNIEXPORT void JNICALL Java_HelloWorld_print (JNIEnv *, jobject); #ifdef __cplusplus } #endif #endif ---------------------- 4. writing c source code for jni ------- #include <jni.h> #include <stdio.h> #include "HelloWorld.h" JNIEXPORT void JNICALL Java_HelloWorld_print(JNIEnv *env, jobject obj) { printf("Hello World!\n"); return; } -------- 5. compile c programing and create .so gcc -o libHelloWorld.so HelloWorld.c -shared -fpic -lcrypt -I/home/user/home-platform/classpath/include Therefore, in the folder /home/user/jni, there are file HelloWorld.c HelloWorld.class HelloWorld.h HelloWorld.java libHelloWorld.so then I run "jamvm HelloWorld" and the error appears java.lang.UnsatisfiedLinkError: Native library `HelloWorld' not found (as file `libHelloWorld.so') in gnu.classpath.boot.library.path and java.library.path at java.lang.Runtime.loadLibrary(Runtime.java:763) at java.lang.System.loadLibrary(System.java:662) at HelloWorld.<clinit>(HelloWorld.java:7) I try to copy libHelloWorld.so in to my boot library path which is Boot Library Path: /home/user/home-platform/classpath/lib/classpath May I have some suggestions or comments about how should i solve this problem? or am i doing anything wrong in the steps above? -- View this message in context: http://www.nabble.com/Error-when-using-JNI-tp20930484p20930484.html Sent from the JamVM mailing list archive at Nabble.com. |