0

I'm trying to implement a simple HelloWorld application with JNI. To call the c function from Java. I created a java class:

class HelloWorld{
private native void print();
public static void main(String[] args){
    new HelloWorld().print();


}

static{
    System.load("c://jni_training//HelloWorld.dll");
}

}

then generated a .h file, created c implementation and successfuly generated the .dll. But I cannot execute java HelloWorld...I see exception

Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\jni_training\Hello World.dll: Can't find dependent libraries 
   at java.lang.ClassLoader$NativeLibrary.load(Native Method) 
   at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1928) 
   at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1825) 
   at java.lang.Runtime.load0(Runtime.java:792) 
   at java.lang.System.load(System.java:1059) 
   at HelloWorld.<clinit>(HelloWorld.java:10

What the issue?

user1379574
  • 689
  • 4
  • 11
  • 23
  • Can you paste the error message as text as I cannot read the image – mmmmmm Jul 06 '12 at 11:35
  • Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\jni_training\Hello World.dll: Can't find dependent libraries at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1928) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1825) at java.lang.Runtime.load0(Runtime.java:792) at java.lang.System.load(System.java:1059) at HelloWorld.(HelloWorld.java:10) – user1379574 Jul 06 '12 at 11:40
  • Is there any specific reason why you are using `System.load` with a hardcoded path instead of `System.loadLibrary` using a predefined library search path? – Pavel Zdenek Jul 07 '12 at 10:48
  • no, there is no reason. I doesn't have any specific sense. I've investigated my dll with dependecy walker and noticed that it requires MSVCR90.dll.... here is the problem....how to solve it? – user1379574 Jul 09 '12 at 07:22

2 Answers2

0

I had a similar problem, If you know for sure that msvcr90.dll is what is dependency then you can have multiple options.

  1. Put the dll in java library path , just do System.out.println(System.getProperty("java.library.path"));and you know what is the library path, and copy your dll file into one of the directory.
  2. load the dll same way you are loading the HelloWorld.dll, Refer : Nice explanation
Abhiram mishra
  • 1,597
  • 2
  • 14
  • 34
0

If that DLL is not in C++ then you'll have to interface via a CLI class morphism.

Olivier10178
  • 191
  • 11