Unsatisfied Link Error with JNI example

Discussion in 'Java' started by allelopath, Jan 4, 2005.

  1. allelopath

    allelopath Guest

    I am trying to do a JNI example but getting an UnsatisfiedLinkError.
    I am following the example at:
    http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jniexamp.html
    I can't follow it exactly because I'm doing it in Eclipse (Is this a bad
    word in this forum?)
    I created and compilled the C file per the instructions.

    I add the path that the .so file is on to the java.library.path in Eclipse
    by going to Run -> Run... -> Arguments -> VM Arguments and adding
    -Djava.library.path=/path/to/so/file/. I added the lines to check the
    library path has been set and it is what I would expect (ie it has the
    path to the .so file)

    What am I doing wrong?

    class ReadFile
    {
    // native method declaration
    native byte[] loadFile(String name);

    // load the library
    static
    {
    System.loadLibrary("libnativelib"); // error here
    }

    public static void main(String args[])
    {
    String libraryPath = System.getProperty("java.library.path",".");
    System.out.println ("library path = " + libraryPath);

    byte buf[];

    // create class instance
    ReadFile mappedFile=new ReadFile();

    // call native method to load ReadFile.java
    buf=mappedFile.loadFile("ReadFile.java");

    // print contents of ReadFile.java
    for(int i=0;i<buf.length;i++)
    {
    System.out.print((char)buf);
    }
    }

    }
    allelopath, Jan 4, 2005
    #1
    1. Advertising

  2. Hi,

    With Eclipse, under windows ( I guess it is the same for Linux ) :
    you need to put the .dll ( or .so in your case ) in the project directory.

    right-click on your project, in the 'info' tab check the 'location'.
    that's were you are to put the C library.

    Hope it helped...

    --p

    allelopath wrote:
    > I am trying to do a JNI example but getting an UnsatisfiedLinkError.
    > I am following the example at:
    > http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jniexamp.html
    > I can't follow it exactly because I'm doing it in Eclipse (Is this a bad
    > word in this forum?)
    > I created and compilled the C file per the instructions.
    >
    > I add the path that the .so file is on to the java.library.path in Eclipse
    > by going to Run -> Run... -> Arguments -> VM Arguments and adding
    > -Djava.library.path=/path/to/so/file/. I added the lines to check the
    > library path has been set and it is what I would expect (ie it has the
    > path to the .so file)
    >
    > What am I doing wrong?
    >
    > class ReadFile
    > {
    > // native method declaration
    > native byte[] loadFile(String name);
    >
    > // load the library
    > static
    > {
    > System.loadLibrary("libnativelib"); // error here
    > }
    >
    > public static void main(String args[])
    > {
    > String libraryPath = System.getProperty("java.library.path",".");
    > System.out.println ("library path = " + libraryPath);
    >
    > byte buf[];
    >
    > // create class instance
    > ReadFile mappedFile=new ReadFile();
    >
    > // call native method to load ReadFile.java
    > buf=mappedFile.loadFile("ReadFile.java");
    >
    > // print contents of ReadFile.java
    > for(int i=0;i<buf.length;i++)
    > {
    > System.out.print((char)buf);
    > }
    > }
    >
    > }
    >
    P. Barthelemy, Jan 4, 2005
    #2
    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. Mark
    Replies:
    9
    Views:
    702
    Steve W. Jackson
    Jan 16, 2004
  2. Replies:
    1
    Views:
    22,249
    Kari Ikonen
    Feb 6, 2005
  3. cppaddict
    Replies:
    4
    Views:
    20,195
    Gordon Beaton
    May 20, 2005
  4. Dag Sunde
    Replies:
    8
    Views:
    2,638
    Dag Sunde
    Jan 5, 2007
  5. Ten Blade
    Replies:
    5
    Views:
    897
    Roedy Green
    Jul 16, 2011
Loading...

Share This Page