简体   繁体   中英

Exception in thread “main” java.lang.UnsatisfiedLinkError 3

Hi guys i have tried all the solutions like java -Djava.library.path=. demo adding the dll path to PATH java -Djava.library.path=c:\\JNI\\demo.dll demo

But still the above error.

Here is my java code..

class demo
{
    public native void printline();
    public static void main(String[]args)
    {
        new demo().printline();
    }
}

Here is my c code...

#include<stdio.h>
#include<jni.h>

#include "demo.h"

JNIEXPORT void JNICALL Java_demo_printline(JNIEnv *a, jobject b)
{
    printf("Hello wrold!!!");
    return;
}

Steps for compiling and running,

  1. javac demo.java
  2. javah demo
  3. gcc -c -I"c:\\jdk1.7.0_55\\include" -I"c:\\jdk1.7.0_55\\include\\win32" demo.c
  4. gcc -Wl,--add-stdcall-alias -shared -o demo.dll demo.c
  5. java -Djava.library.path=c:\\JNI\\demo.dll demo

Am i going wrong somewhere?

can someone please help me out,.

Try Run-Time Loading of the dll file within the java code in a static block like:

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

should give you the output.

Moreover make sure that dll file generated is x32 or x64 according to the gcc compiler in use.

looking for "JNI hello world" (or many other terms, possibly), would have given you the answer.

for example:

http://www3.ntu.edu.sg/home/ehchua/programming/java/JavaNativeInterface.html

  • you need to load the library inside your java code
  • you need to specify the path to the directory of the library, not to the library itsself, in java.library.path

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM