Operating System - HP-UX
1756471 Members
3443 Online
108847 Solutions
New Discussion юеВ

Re: UnsatisfiedLinkError when trying to load shared library containing native method

 
David Calkins_2
Occasional Contributor

UnsatisfiedLinkError when trying to load shared library containing native method

I'm using Java 1.1.8.04 on HP-UX 10.20.

I've created a Java class with a native method. I then used javah -jni MyClass to generate the native header file. I then implemented the method in C and compiled it into a shared library (.sl).

When I try and run the Java class, I get the following error:

java.lang.UnsatisfiedLinkError: no MyLib in shared library path
at java.lang.Runtime.loadLibrary(Runtime.java)
at java.lang.System.loadLibrary(System.java)
at
at java.lang.Thread.init(Thread.java)

The library is actually libMyLib.sl. In the Java class, I have

static {
System.loadLibrary("MyLib");
}

And, I've verified that the directory containing the shared library is in the SHLIB_PATH and LD_LIBRARY_PATH variables.

Any idea why its not able to find the library?
2 REPLIES 2
David Calkins_2
Occasional Contributor

Re: UnsatisfiedLinkError when trying to load shared library containing native method

Well, thanks to HP-UX tech support, I was able to figure out the problem. They pointed me to the following document:

http://www.hp.com/products1/unix/java/infolibrary/prog_guide/java1/JNI_java1.html

By using this document I was able to figure out that the problem was caused, not because my library couldn't be found, but rather, because my library wasn't linked with some other necessary libraries.

Once I recompiled my shared library and added the following libraries to my link command, everything worked.

-lCsup -lstream -lstd

Hopefully this will help anyone else stuck in this situation.
GRANDIERE
Frequent Advisor

Re: UnsatisfiedLinkError when trying to load shared library containing native method

I had a some close problem this my library libLibrairie.sl (SHLIB_PATH=/patch/myenv).
I called the methode like this

System.loadLibrary ("libLibrairie");

It did not work.

System.loadLibrary ("Librairie");

Works better because unix adds the prefix "lib" by its owns.
I hope it will help you
By.
Emmanuel