• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi:
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);
static
{
System.loadLibrary("ShipServer");
}
//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
{
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
{
public:
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
ShipServer.cpp
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
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:
export LD_LIBRARY_PATH=/home/java:$LD_LIBRARY_PATH:
Could you please help me to resolve this problem?
Your help would be highly appreciated...
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you been able to solve the problem ? I am facing a similar problem.
 
Ranch Hand
Posts: 919
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
HTH.
 
Hey, sticks and stones baby. And maybe a wee mention of my stuff:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic