Results 1 to 3 of 3
  1. #1
    JNB
    JNB is offline Member
    Join Date
    Jul 2011
    Posts
    2
    Rep Power
    0

    Default UnsatisfiedLinkError using JNI

    Hi,

    I have created a simple JNI Java and c++ classes. The code looks as below. I was able to compile the code without errors. But when I'm trying to run the java class I get the UnsatisfiedLinkError error. I have the necessary dll file in the same location as the Java class file. Please help

    Error:
    C:\foo>java JNIFoo
    Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\foo\foo.dll: Can't find dependent libraries
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.jav a:1807)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java :1732)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1028)
    at JNIFoo.<clinit>(JNIFoo.java:5)
    Could not find the main class: JNIFoo. Program will exit.

    Even java -Djava.library.path=C:\foo JNIFoo doesnt help

    Java class:
    public class JNIFoo {
    public native String nativeFoo();

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

    public void print () {
    String str = nativeFoo();
    System.out.println(str);
    }

    public static void main(String[] args) {
    (new JNIFoo()).print();
    return;
    }
    }

    C++ class: (Compiled in Visual Studio 2008)

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "jni.h"
    #include "JNIFoo.h"

    JNIEXPORT jstring JNICALL Java_JNIFoo_nativeFoo (JNIEnv *env, jobject obj)
    {
    jstring ret = 0;

    char *buf = (char*)malloc(10);
    strcpy(buf, "From Native");
    jstring jstrBuf = env->NewStringUTF(buf);

    return jstrBuf;

    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    JNB, don't double post. Your other thread has been closed.

    db

  3. #3
    Jhovarie is offline Banned
    Join Date
    Feb 2011
    Posts
    65
    Rep Power
    0

Similar Threads

  1. UnsatisfiedLinkError using JNI
    By JNB in forum New To Java
    Replies: 2
    Last Post: 07-14-2011, 10:21 AM
  2. UnsatisfiedLinkError on dll load
    By Bharath_M in forum Advanced Java
    Replies: 8
    Last Post: 04-11-2011, 12:23 PM
  3. UnsatisfiedLinkError
    By leepan2008 in forum Advanced Java
    Replies: 4
    Last Post: 01-07-2011, 05:40 AM
  4. UnsatisfiedLinkError
    By Hussain Ali in forum Eclipse
    Replies: 2
    Last Post: 04-11-2010, 08:59 AM
  5. Replies: 0
    Last Post: 08-12-2007, 04:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •