Unsatisfied Link error
Hi, I know that there are a lot of question related to this topic. But I couldn't find a solution to it.
I got this Unsatisfied Link error when I ran the program:
Exception in thread "main" java.lang.UnsatisfiedLinkError: /.autofs/homes/guest1/jhuang/project/samples/JNI/libhello.so: /.autofs/homes/guest1/jhuang/project/samples/JNI/libhello.so: ELF file's phentsize not the expected size
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1382)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1306)
at java.lang.Runtime.loadLibrary0(Runtime.java:749)
at java.lang.System.loadLibrary(System.java:820)
at HelloWorld.<clinit>(HelloWorld.java:5)
I have set the LD_LIBRARY_PATH to my shared library.
What is the problem here?
Thanks a lot!
Jim
[909 byte] By [
yeahking] at [2007-9-26 5:12:13]

you may have this problem if you put the extension of your library inside "LoadLibrary" call. I can't say it for sure for LINUX, but under windows, I had the same when i tried to load a dll specifying it as "name.dll". When I put the name without extension - as
System.loadLibrary("name") - it worked fine.
EDemch at 2007-6-29 19:13:51 >

> >/.autofs/homes/guest1/jhuang/project/samples/JNI/libhe
> lo.so:
> >ELF file's phentsize not the expected size
>
> My guess would be that something is wrong with the so.
> Like you are using an unusual compiler/linker
> option.
im having this exact same problem...
and its possible that it could be compile/linker problems...
in the tutorial and somewhere else i saw people compiling the C code with
cc -G -I/usr/include/java/ -I/usr/include/java/linux foo.c -o libfoo.so
but i get errors when using cc and -G and gcc doesnt even like the -G...so i get rid of these to make my .so
so what i really need to know is really how to build a .so properly :)
alex
goto whatever editor u r using and check where the project is created. Example, in eclipse goto project->properties and check the 'info'. Here it will show you the path where the project is created. Copy the library (dll) in that folder and try running ur java app.
i too was facing the same problem and i tried fixing the error by setting library path etc but in vain.
If you have the Java class declared in a package com.mycompany.jni.MyClass, please add it as follows.
javah -jni com.mycompany.jni.MyClass
You will get the following header file..
com_mycompany_jni_MyClass.h
with the following header signature inside this file
JNIEXPORT void JNICALL Java_com_mycompany_jni_MyClass_print
(JNIEnv *, jobject, jstring);
Include this header as is in the .c/.cpp file and after that create the DLL / .so file.