jni trouble

S

stef

Hi
Please JNI experts, help me :

Under Linux rh 7.3
I try


class hello
{
static { System.loadLibrary("hello"); }


public native void printHello();

public static void main(String[] args)
{
System.out.println("Hello, world!");
}
}

ok,
$ javac hello.java
$ javah -jni hello

C side :
#include "hello.h"
#include "jni.h"

JNIEXPORT void JNICALL Java_hello_printHello( JNIEnv *env, jobject obj )
{
printf("Hello world!\n");
return;
}


then :

gcc -I ${JAVA_HOME}/include/ -I ${JAVA_HOME}/include/linux/ -o
hello.so -shared -fpic -lc hello.c

right, now
I set
export LD_LIBRARY_PATH=<path of hello.so>

and now :
$ java hello
gives

Exception in thread "main" java.lang.UnsatisfiedLinkError: no hello in
java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1491)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:834)
at hello.<clinit>(hello.java:3)


I don't understand
(Except the JNI, I can compile/run some java classes of course !!)


please help me guys...

thanx
 
G

Gordon Beaton

gcc -I ${JAVA_HOME}/include/ -I ${JAVA_HOME}/include/linux/ -o
hello.so -shared -fpic -lc hello.c

right, now
I set
export LD_LIBRARY_PATH=<path of hello.so>

and now :
$ java hello
gives

Exception in thread "main" java.lang.UnsatisfiedLinkError: no hello
in java.library.path

Make sure your library is called "libhello.so". The argument to
System.loadLibrary() is correct ("hello").

Also, you probably don't need to link the c library (-lc) although
this isn't related to your problem.

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top