JNI linux problems

I

Ilghiz Ibraghimov

Dear All,

would you suggest me how to solve my problem!

I have SuSE Linux 7.3, j2sdk1.4 and compile one web example of JNI:

gcc -c JNIPrintWrapperImpl.cpp
ar cru libJNIPrintMessage.so JNIPrintWrapperImpl.o
export LD_LIBRARY_PATH=.
java JNIPrintMain

gives the following message error:

Exception in thread "main" java.lang.UnsatisfiedLinkError:
/home2/ilgis/JAVA/DEITEL/2/chapters/appG/figG_01/libJNIPrintMessage.so:
/home2/ilgis/JAVA/DEITEL/2/chapters/appG/figG_01/libJNIPrintMessage.so:
ELF file's phentsize not the expected size

Thank you for your ideas!

Sincerely

Ilghiz

*************************************
public class JNIPrintMain{
public static void main( String args[] )
{ JNIPrintWrapper wrapper = new JNIPrintWrapper();
wrapper.printMessage( "Hello World\n" );
}
}
*************************************
public class JNIPrintWrapper {
static { System.loadLibrary( "JNIPrintMessage" ); }
public native void printMessage( String message );
}
*************************************
#include <iostream.h>
#include "JNIPrintWrapper.h"
JNIEXPORT void JNICALL Java_JNIPrintWrapper_printMessage
( JNIEnv * env, jobject thisObject, jstring message )
{
jboolean copied;
const char* charMessage =
env->GetStringUTFChars( message, &copied );
cout << charMessage;
env->ReleaseStringUTFChars( message, charMessage );
}
*************************************
 
G

Gordon Beaton

I have SuSE Linux 7.3, j2sdk1.4 and compile one web example of JNI:

gcc -c JNIPrintWrapperImpl.cpp
ar cru libJNIPrintMessage.so JNIPrintWrapperImpl.o
export LD_LIBRARY_PATH=.
java JNIPrintMain

gives the following message error:

Exception in thread "main" java.lang.UnsatisfiedLinkError:

That isn't how to create a shared library.

Try this instead:

gcc -fPIC -shared JNIPrintWrapperImpl.cpp -o libJNIPrintMessage.so

/gordon
 
G

Gordon Beaton

undefined symbol: __gxx_personality_v0

There is no __gxx_... symbols in my code, but it is in the *.so
library, and I cannot understand where to find it, please, help me
once more!

Are you using gcc 3.2?

Try adding a link option to the command line:

gcc -fPIC -shared -lstdc++ JNIPrintWrapperImpl.cpp -o libJNIPrintMessage.so

See also (although I'm not sure if this is the same problem):
http://gcc.gnu.org/onlinedocs/gcc-3.2.3/gcc/Java-Exceptions.html#Java Exceptions

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

JNI and GetFieldID 12
JNI/Linux/chown 6
JNI Problems with MINGW32 2
JNI generic type of jobject 6
Problem with JNI and Tomcat 6
JNI Error in passing array 0
JNI 1
JNI and Web Services 3

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top