Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > error: java.lang.UnsatisfiedLinkError: Can't load library:

Reply
Thread Tools

error: java.lang.UnsatisfiedLinkError: Can't load library:

 
 
gopinath511 gopinath511 is offline
Junior Member
Join Date: Jan 2009
Posts: 3
 
      01-07-2009
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:

$ <java_dir>/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.

$ <java_dir>/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 <stdio.h>
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<java_dir>/include \
-I<java_dir>/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
$ <java_dir>/bin/java TestJava2CallingNative cImpl

This is what i have done...

While extecuting the
$ <java_dir>/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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
to load or not to load =?Utf-8?B?cm9kY2hhcg==?= ASP .Net 3 08-30-2006 08:20 AM
Load Balancing / Load Sharing over parallel paths ciscortp@hotmail.com Cisco 1 11-21-2005 03:57 PM
page not load / freeze / long time to load roni ASP .Net 1 08-30-2005 09:15 PM
Page Load and webcontrol page load venky ASP .Net 5 07-11-2005 03:16 PM
beginning page load immediately on postback with a long load time ? Mad Scientist Jr ASP .Net 7 06-30-2004 07:40 PM



Advertisments