This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

sridevi kumar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.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(
at java.lang.System.loadLibrary(
at ShipServer.main(
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...
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you been able to solve the problem ? I am facing a similar problem.
George Brown
Ranch Hand
Posts: 919
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!