How does one compile/link the shared object for JNI modules.
Here is an example the shows the problems I am having. I follow the steps
in the Tutorial; namely:
1) Create Java code (HelloWorld.java)
2) Compile
3) Create header for stubs (HelloWorld.h)
4) Create C/C++ code (HelloWorld.C)
5) Compile/link with jni.h
6) Set LD_LIBRARY_PATH
7) Execute
I end up with the following error message when I try to execute:
Exception in thread "main" java.lang.UnsatisfiedLinkError:
/home/klmcw/src/Java/JNI/libhwrld.so: /home/klmcw/src/Java/JNI/libhwrld.so:
ELF file's phentsize not the expected size
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Compiled Code)
at java.lang.ClassLoader.loadLibrary(Compiled Code)
at java.lang.Runtime.loadLibrary0(Compiled Code)
at java.lang.System.loadLibrary(Compiled Code)
at HelloWorld.<clinit>(HelloWorld.java:15)
What is this ELF file phentsize error about? Any ideas? Thanks in advance.
I have included the source below just in case.
Kevin
-+-+-+-+-+-+-+-+-+-+-+-CUT-+-+-+-+-+-+-+-+-+-+-+-
HelloWorld.java
class HelloWorld {
String s = null;
public HelloWorld() {
s = HelloWorldAux();
}
public native String HelloWorldAux();
public String toString() {
return this.s;
}
static {
System.loadLibrary("hwrld");
}
static public int main(String[] args) {
try {
HelloWorld hw = new HelloWorld();
System.out.println(hw.toString());
} finally {
return 0;
}
}
}
-+-+-+-+-+-+-+-+-+-+-+-CUT-+-+-+-+-+-+-+-+-+-+-+-
HelloWorld.C
#include "HelloWorld.h"
JNIEXPORT jstring JNICALL
Java_HelloWorld_HelloWorldAux(JNIEnv *jenv, jobject jobj)
{
static char hw[] = "Hello, World!";
return jenv->NewStringUTF(hw);
}
-+-+-+-+-+-+-+-+-+-+-+-CUT-+-+-+-+-+-+-+-+-+-+-+-
Makefile
INCLUDES=-I/opt/web/jdk1.2/include -I/opt/web/jdk1.2/include/linux
CXXFLAGS=-c -fpic -O2 $(INCLUDES)
all: libhwrld.so
libhwrld.so: HelloWorld.C HelloWorld.h
g++ $(CXXFLAGS) $< -o $@
HelloWorld.h: HelloWorld.class
javah -jni HelloWorld
HelloWorld.class: HelloWorld.java
javac -O HelloWorld.java
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]