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

Discussion in 'Software' started by gopinath511, Jan 7, 2009.

  1. gopinath511

    gopinath511

    Joined:
    Jan 7, 2009
    Messages:
    1
    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/cIm
    pl

    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
    gopinath511, Jan 7, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. emerald
    Replies:
    3
    Views:
    12,746
    The Modfather
    May 14, 2006
  2. Stanly1
    Replies:
    0
    Views:
    2,382
    Stanly1
    Sep 22, 2006
  3. prakash.nmsp@gmail.com

    Exception in thread "main" java.lang.NoClassDefFoundError:

    prakash.nmsp@gmail.com, Jun 29, 2007, in forum: Software
    Replies:
    0
    Views:
    1,405
    prakash.nmsp@gmail.com
    Jun 29, 2007
  4. Shalz
    Replies:
    0
    Views:
    1,318
    Shalz
    Mar 8, 2008
  5. asha.03.4u

    Java.lang.OutofMemory.Exception

    asha.03.4u, Mar 30, 2009, in forum: Software
    Replies:
    2
    Views:
    974
    susith
    Apr 3, 2009
Loading...

Share This Page