Hello,
I'm having problems with linking libraries in a JNI method in java
1.2...
My machine is a RedHat 5.2 box with kernel 2.2.3.
I have succesfully got jdk1.2 installed and run some of the Demos...
The JNI code works fine under jdk117, but dies under 1.2 with:
UnsatisfiedLinkError: /home/crispin/testJNI/libJNITest.so:
/home/crispin/testJNI/libJNITest.so: undefined symbol: fstat
The following is a small piece of code which produces the error, and the
commands I use to compile and run it.
I would be most grateful if anyone can help me with this.
Thanks,
Crispin
---------------------------
The test class
---------------------------
class JNITest {
JNITest() {
}
static {
System.loadLibrary("JNITest");
}
public native void JNICall(int aParam);
static int main(String[] params) {
JNITest t = new JNITest();
t.JNICall(1);
return 1;
}
}
---------------------------
generated by javah
---------------------------
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class JNITest */
#ifndef _Included_JNITest
#define _Included_JNITest
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: JNITest
* Method: JNICall
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_JNITest_JNICall
(JNIEnv *, jobject, jint);
#ifdef __cplusplus
}
#endif
#endif
------------------------------
the c code
------------------------------
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include "JNITest.h"
JNIEXPORT void JNICALL Java_JNITest_JNICall
(JNIEnv *e, jobject o , jint i) {
struct stat buf;
int fdes = open("testFile",O_RDONLY);
fstat(fdes,&buf);
}
------------------------------
compiled by:
------------------------------
javac JNITest.java
javah JNITest
gcc -I /opt/jdk1.2/include/ -I /opt/jdk1.2/include/linux/ -fPIC -c
JNITest.c
gcc -shared -Wl,-soname,libJNITest.so.1.0 -o libJNITest.so.1.0 JNITest.o
mv libJNITest.so.1.0 libJNITest.so
------------------------------
running with:
------------------------------
java JNITest
------------------------------
produces:
------------------------------
[crispin@pgr2 testJNI]$ java JNITest
Exception in thread "main" java.lang.UnsatisfiedLinkError:
/home/crispin/testJNI/libJNITest.so:
/home/crispin/testJNI/libJNITest.so: undefined symbol: fstat
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 JNITest.<clinit>(JNITest.java:5)
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]