T
tony_lincoln
Dear Friends,
I am using JNI to call C++ codes from Java, under Linux. This calling
worked in my Win2000, but not in Linux. The source codes came from
official java website:
*********************************************************************
//HelloWorld.java
class HelloWorld {
public native void displayHelloWorld();
static {
System.loadLibrary("hello");
}
public static void main(String[] args) {
new HelloWorld().displayHelloWorld();
}
}
**********************************************************************
I compiled it:
Javac HelloWorld.java
Javah -jni HelloWorld
then compile the following c++ codes:
**********************************************************************
//HelloWorldImp.c:
#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
printf("Hello world!\n");
return;
}
************************************************************************
gcc *.c -shared -o hello.so
Then "java HelloWorld",
The following error comes:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no hello in
java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1517)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:834)
at HelloWorld.<clinit>(HelloWorld.java:5)
I tried to copy the hello.so into /usr/lib/java/jre/lib/i386, but it
did not work.
Why and how?
I am using JNI to call C++ codes from Java, under Linux. This calling
worked in my Win2000, but not in Linux. The source codes came from
official java website:
*********************************************************************
//HelloWorld.java
class HelloWorld {
public native void displayHelloWorld();
static {
System.loadLibrary("hello");
}
public static void main(String[] args) {
new HelloWorld().displayHelloWorld();
}
}
**********************************************************************
I compiled it:
Javac HelloWorld.java
Javah -jni HelloWorld
then compile the following c++ codes:
**********************************************************************
//HelloWorldImp.c:
#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
printf("Hello world!\n");
return;
}
************************************************************************
gcc *.c -shared -o hello.so
Then "java HelloWorld",
The following error comes:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no hello in
java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1517)
at java.lang.Runtime.loadLibrary0(Runtime.java:788)
at java.lang.System.loadLibrary(System.java:834)
at HelloWorld.<clinit>(HelloWorld.java:5)
I tried to copy the hello.so into /usr/lib/java/jre/lib/i386, but it
did not work.
Why and how?