ELF file's phentsize not the expected size - ERROR on Linux
843829Feb 21 2002 — edited Feb 21 2002I followed all the steps shown on the javasoft/tutorial on JNI and created the following files
ThreadTool.c
~~~~~~~~~~~~~~~~~~
#include <jni.h>
#include "ThreadTool.h"
#include <jvmdi.h>
JNIEXPORT jint JNICALL Java_ThreadTool_getThreadStatus
(JNIEnv *env, jclass clazz, jobject thread)
{
jint threadStatus;
jint suspendStatus;
jvmdiError error = JVMDI_GetThreadStatus (env, thread, &threadStatus, &suspendStatus);
return (threadStatus);
}
ThreadTool.h
~~~~~~~~~~
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class ThreadTool */
#ifndef IncludedThreadTool
#define IncludedThreadTool
#ifdef __cplusplus
extern "C" {
#endif
#undef ThreadTool_THREAD_STATUS_UNKNOWN
#define ThreadTool_THREAD_STATUS_UNKNOWN -1L
#undef ThreadTool_THREAD_STATUS_ZOMBIE
#define ThreadTool_THREAD_STATUS_ZOMBIE 0L
#undef ThreadTool_THREAD_STATUS_RUNNING
#define ThreadTool_THREAD_STATUS_RUNNING 1L
#undef ThreadTool_THREAD_STATUS_SLEEPING
#define ThreadTool_THREAD_STATUS_SLEEPING 2L
#undef ThreadTool_THREAD_STATUS_MONITOR
#define ThreadTool_THREAD_STATUS_MONITOR 3L
#undef ThreadTool_THREAD_STATUS_WAIT
#define ThreadTool_THREAD_STATUS_WAIT 4L
#undef ThreadTool_SUSPEND_STATUS_SUSPENDED
#define ThreadTool_SUSPEND_STATUS_SUSPENDED 1L
#undef ThreadTool_SUSPEND_STATUS_BREAK
#define ThreadTool_SUSPEND_STATUS_BREAK 2L
/*
* Class: ThreadTool
* Method: getThreadStatus
* Signature: (Ljava/lang/Thread;)I
*/
JNIEXPORT jint JNICALL Java_ThreadTool_getThreadStatus
(JNIEnv *, jclass, jobject);
#ifdef __cplusplus
}
#endif
#endif
ThreadTool.java (This is my test class)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public class ThreadTool {
public static final int THREAD_STATUS_UNKNOWN = -1;
public static final int THREAD_STATUS_ZOMBIE = 0;
public static final int THREAD_STATUS_RUNNING = 1;
public static final int THREAD_STATUS_SLEEPING = 2;
public static final int THREAD_STATUS_MONITOR = 3;
public static final int THREAD_STATUS_WAIT = 4;
public static final int SUSPEND_STATUS_SUSPENDED = 1;
public static final int SUSPEND_STATUS_BREAK = 2;
public static native int getThreadStatus (Thread t);
static {
String currpath = System.getProperty("java.library.path");
String newpath = currpath+":/home/apota/";
System.setProperty("java.library.path", newpath);
System.loadLibrary ("ThreadTool");
}
public static void main(String[] args) {
Reaper rp = new Reaper(1000, "apota");
Reaper rp1 = new Reaper(2000, "drice");
rp.start();
rp1.start();
while (true) {
System.out.println("Apota thread "+ThreadTool.getThreadStatus(rp));
System.out.println("Drice thread "+ThreadTool.getThreadStatus(rp1));
}
}
}
I use the following command to compile on Linux
gcc -I/usr/local/java/include -I/usr/local/java/include/linux ThreadTool.c -c -o libThreadTool.so
When I run the java program to test it, I get the following
Exception in thread "main" java.lang.UnsatisfiedLinkError: /usr/home/apota/libThreadTool.so: /usr/home/apota/libThreadTool.so: ELF file's phentsize not the expected size
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1419)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1343)
at java.lang.Runtime.loadLibrary0(Runtime.java:749)
at java.lang.System.loadLibrary(System.java:820)
at ThreadTool.<clinit>(ThreadTool.java:21)
Whats going on?
(FYI: I am trying ot get the status of a Thread in Java using the JVMDI C API)