wood burning stoves
The moose likes Linux / UNIX and the fly likes How to solve UnsatisfiedLinkError? - URGENT...please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "How to solve UnsatisfiedLinkError? - URGENT...please help" Watch "How to solve UnsatisfiedLinkError? - URGENT...please help" New topic

How to solve UnsatisfiedLinkError? - URGENT...please help

sridevi kumar
Ranch Hand

Joined: Oct 17, 2001
Posts: 31
I am trying to implement JNI in HP-UX 10.20. We are using jdk1.1.8.
I am getting UnsatisfiedLinkError even though i set the library path.
Please go through the following steps:
1) The .java file is as follows:
class ShipInterface
public native int getCPPObjPointer();
public native String parseShipRequest(String strRequest, int ptrShip);
//other methods...
2) I complied this .java file using javac
3) javah -jni ShipInterface
4) Actually, the following java class invokes the native methods
public class ShipServer
String strRequest = "parse this request";
ShipInterface m_objShipInterface = new ShipInterface();
int ptrShip = m_objShipInterface.getCPPObjPointer();
String strReply = m_objShipInterface.parseShipRequest(strRequest, ptrShip);
5) Now .cpp file (the name of the file is ShipServer.cpp)
#include <jni.h>
#include "ShipInterface.h"
#include <stdio.h>
class MyShip
char* parseRequest(const char* strRequest)
char* strReply = "Return this reply";
return (strReply);

JNIEXPORT jint JNICALL Java_ShipInterface_getCPPObjPointer
(JNIEnv * jEnv, jobject jObj)
MyShip *objMyShip = new MyShip();
return( (jint) objMyShip);
JNIEXPORT jstring JNICALL Java_ShipInterface_parseShipRequest
(JNIEnv * env, jobject obj, jstring strInput, jint ptr)
//convert java type 'String' to C++ type 'char *'
const char * strRequest = env->GetStringUTFChars(strInput, 0);
MyShip *objMyShip = (MyShip *)ptr;
char * strReply = objMyShip->parseRequest( strRequest );
env->ReleaseStringUTFChars(strInput, strRequest);
return env->NewStringUTF(strReply);
6) Now, i had compiled .cpp as follows:
g++ -fpic -shared -c -I/opt/java/include -I/opt/java/include/hp-ux
7) Now, i had created the shared library as follows:
/usr/ccs/bin/ld -b -o ShipServer.sl ShipServer.o
8) Now, i had set the library path as follows:
export SHLIB_PATH=/home/Java:$SHLIB_PATH:
[Note 1: The directory /home/Java contains the .sl file ]
[ Note 2: For hp-ux, we need to set SHLIB_PATH but not LD_LIBRARY_PATH]
9) When i try to execute ShipServer.class file (by issuing the command
jre ShipServer ), i am getting the following error:
java.lang.UnsatisfiedLinkError: no ShipServer in shared library path
at java.lang.Runtime.loadLibrary(Runtime.java)
at java.lang.System.loadLibrary(System.java)
at ShipServer.main(ShipServer.java:313)
Note 1: Even though, i had set the library path, i am getting this error.
Note 2: I had also tried to set the library path as follows:
Could you please help me to resolve this problem?
Your help would be highly appreciated...

Joined: Jun 16, 2002
Posts: 1
Have you been able to solve the problem ? I am facing a similar problem.
George Brown
Ranch Hand

Joined: Sep 26, 2000
Posts: 919
I never saw this post back in February, otherwise I would have replied.
The simple answer is that the link command is off the mark. It should be:

The rest should then work ok. BTW, the step at the end where LD_LIBRARY_PATH is used is pointless, as pointed out earlier in the original post (point 8) the HP-UX version of that particular environment variable is SHLIB_PATH.
I agree. Here's the link: http://aspose.com/file-tools
subject: How to solve UnsatisfiedLinkError? - URGENT...please help
It's not a secret anymore!