Operating System - HP-UX
1752821 Members
4305 Online
108789 Solutions
New Discussion

error: java.lang.UnsatisfiedLinkError: Can't load library: /home/nalgo01/cImpl

 
nallamolu
Advisor

error: java.lang.UnsatisfiedLinkError: Can't load library: /home/nalgo01/cImpl

Hi World,

In the below u can find a sample Java™ program that calls a native method, which has a C implementation:


OS : HP-UX IA64
java : 1.6


Here is the sample program.

####################################

//
// File TestJava2CallingNative.java
//
class TestJava2CallingNative {
native static void sayHelloWorld();
public static void main(String args[])
{
String libname = args[0];
try {
System.loadLibrary(libname);
System.out.println("Library " +
libname + " successfully loaded");
}
catch (UnsatisfiedLinkError Err) {
System.out.println("error: " + Err);
return;
}
System.out.println("Calling sayHelloWorld");
sayHelloWorld();
System.out.println("All done");
}
}


Compile this class:

$ /bin/javac -verbose TestJava2CallingNative.java

Output:

TestJava2CallingNative.class

Generate the JNI header file for this class. You must have the current directory in your CLASSPATH for the javah command to find your newly compiled class file.

$ /bin/javah -verbose -jni TestJava2CallingNative

Output:

TestJava2CallingNative.h

#########################################

Here is the sample c code


Here is the sample C native method implementation for sayHelloWorld:

/*
* File cImpl.c
*/
#include "TestJava2CallingNative.h"
#include
JNIEXPORT void JNICALL
Java_TestJava2CallingNative_sayHelloWorld(JNIEnv *env, jclass class)
{
printf("C says HelloWorld via stdio\n");
}

To compile this C source file:

$ cc -Ae +u4 +z -c -mt -I/include \
-I/include/hp-ux cImpl.c

Output:

cImpl.o

Create the shared library containing the native method implementation:

ld -b -o libcImpl.so cImpl.o ( Is this creation correct for HP-UX IA64 )

Output:

libcImpl.so


Have set the path as :
To execute the Java™ program, you must set the SHLIB_PATH environment variable to contain the location of the directory that contains libcImpl.so

Once i set the PATH i did the following steps

$ export SHLIB_PATH=.:$SHLIB_PATH
$ /bin/java TestJava2CallingNative cImpl

This is what i have done...

While extecuting the
$ /bin/java TestJava2CallingNative cImpl
above line i got the error message as

# java TestJava2CallingNative cImpl
error: java.lang.UnsatisfiedLinkError: Can't load library: /home/nalgo01/cImpl

what is the solution for this. Does i need to set any other options while compiling or linking.

Make sure i am using HP-UX IA64.


Any help is apreceated

Thanks in advance
Gopi
21 REPLIES 21
Danny Petterson - DK
Trusted Contributor

Re: error: java.lang.UnsatisfiedLinkError: Can't load library: /home/nalgo01/cImpl

Hi!

Should'nt /home/nalgo01 (absolute path) be in your SHLIB_PATH when thats where clmpl is located?

export SHLIB_PATH=$SHLIB_PATH:/home/nalgo01

Yours
Danny
nallamolu
Advisor

Re: error: java.lang.UnsatisfiedLinkError: Can't load library: /home/nalgo01/cImpl

Hi Danny,

Have tried setting the SHLIB_PATH to /home/nalgo01 (absolute path)

But no result. Same error is being produced

Any help is appreceated

Thanks in advance
Gopi
Dennis Handly
Acclaimed Contributor

Re: error: java.lang.UnsatisfiedLinkError: Can't load library: /home/nalgo01/cImpl

This looks like a continuation of your other two threads:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1300275
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1299685

>what is the solution for this? Do I need to set any other options while compiling or linking?

I have no problems compiling, linking and running this test case using cc(1) and java 1.5. Both in 32 and 64 bit.
And no problems with gcc 4.2.1.
nallamolu
Advisor

Re: error: java.lang.UnsatisfiedLinkError: Can't load library: /home/nalgo01/cImpl

Hi Dennis,

I Compiled the above test case using

# cc +z -c -dynamic +DD64 -Ae +u4 -mt \
-I/include \
-I/include/hpux cImpl.c

It compiled properly, and linked using ld

# ld -b +k +s +std -o libcImpl.so cImpl.o \
-lstd_v2 -lCsup -lunwind -lm

The test application ran successfully

> I have no problems compiling, linking and running this test case using cc(1) and java 1.5. Both in 32 and 64 bit.

Can u post what are the options u have used for compileing and linking using cc.

> And no problems with gcc 4.2.1.

Can u post the options for compiling and linking using gcc.

Dennis one more info needed.

1.) My c application retreives the system related info such as

- pid, No of CPU's, Process CPU
utilization, Aggregate CPU utilization

I retreive these info using getrusage system call.

Q : i have compiled this appication using
the the above cc options. it compiled sucessfully. I linked this appication using the same linking options as above.

When i tried to use the executable it is giving the error as

error: java.lang.UnsatisfiedLinkError: Can't load library: /home/nalgo01/libIA64.so

My question is does these system calls have any other dependencies other than what i used while linking ie ( -lstd_v2 -lCsup -lunwind -lm )

What are the libraries which depend on native system calls such as getrusage.

Any help is apreceated
Thanx in advance
Gopi
nallamolu
Advisor

Re: error: java.lang.UnsatisfiedLinkError: Can't load library: /home/nalgo01/cImpl

Hi Dennis,

Can u look into this once.

Regards,
Gopi
Dennis Handly
Acclaimed Contributor

Re: error: java.lang.UnsatisfiedLinkError: Can't load library: /home/nalgo01/cImpl

>I compiled the above test case using
> cc +z -c -dynamic +DD64 -Ae +u4 -mt \
-I/include \
-I/include/hpux cImpl.c

I left out -dynamic since it is the default.

>linked using ld
>ld -b +k +s +std -o libcImpl.so cImpl.o \
-lstd_v2 -lCsup -lunwind -lm

You must NOT use ld to link aC++ shlibs. You must use aCC -b.

I just used what was documented: ld -b -o libcImpl.so cImpl.o

>Can you post what are the options you have used for compiling and linking using cc.

What you had before.

>Can you post the options for compiling and linking using gcc.

What you had previously.

>Q: I linked this application using the same linking options as above.

Use the cut down ld command.

>When i tried to use the executable it is giving the error as
>error: java.lang.UnsatisfiedLinkError: Can't load library: /home/nalgo01/libIA64.so

This java error is garbage, it doesn't tell you anything.

>does these system calls have any other dependencies other than what i used while linking ie (-lstd_v2 -lCsup -lunwind -lm)

Do not use these aC++ shlibs.

>What are the libraries which depend on native system calls such as getrusage.

They are all in libc.
Dennis Handly
Acclaimed Contributor

Re: error: java.lang.UnsatisfiedLinkError: Can't load library: /home/nalgo01/cImpl

You do know that if you compile with +DD64, you need to run java with -d64.
nallamolu
Advisor

Re: error: java.lang.UnsatisfiedLinkError: Can't load library: /home/nalgo01/cImpl

Hi Dennis,

thanx a lot for u reply :-)

>> >What are the libraries which depend on native system calls such as getrusage.

>They are all in libc.

i have tried that native appication ie which retrives pid, No of CPU's, so on...

I compiled & linked as u have have mentioned.

Linking options :

ld -b -o libIntroscopeHpuxItanium64Stats.so java_interface.o -lc (as u have mentioned all system call libraries are stored in libc )

It got linked properly.

I used this executable in my appication but got an error :

#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# SIGSEGV (11) at pc=c00000000774e1c1, pid=20716, tid=19
#
# Java VM: Java HotSpot(TM) 64-Bit Server VM (1.5.0.11 jinteg:11.07.07-18:21 IA64W mixed mode)
# Problematic frame:
# C [libIntroscopeHpuxItanium64Stats.so+0x21c1] Java_com_wily_introscope_agent_platform_hpux_HPUXPlatformStatisticsBackEnd_getCPUIndexMap+0x191
#



detailed log is atached for clear understanding.

Thanks in Advance Dennis,
Gopi
Dennis Handly
Acclaimed Contributor

Re: error: java.lang.UnsatisfiedLinkError: Can't load library: /home/nalgo01/cImpl

>ld -b -o libIntroscopeHpuxItanium64Stats.so java_interface.o -lc (as you have mentioned all system call libraries are stored in libc)

You shouldn't need to add -lc here.

>I used this executable in my application but got an error:
# Problematic frame: C
[libIntroscopeHpuxItanium64Stats.so+0x21c1] Java_com_wily_introscope_agent_platform_hpux_HPUXPlatformStatisticsBackEnd_g
etCPUIndexMap+0x191

Notice how java cleverly blames your JNI function. :-)

You need to debug your code. Compile with -g and you can use gdb to print out variables.