Java.lang.UnsatisfiedLinkError in my java program :(

I have created a program that uses JNI. I compiled it, generated a header file, created the appropriate C program and created a dll for it.

I am throwing an exception:

Exception on thread "main" java.lang.UnsatisfiedLinkError: D: \ examples \ FirstJNIExample.dll: Cannot find dependent libraries in java.lang.ClassLoader $ NativeLibrary.load (native method) in java.lang.ClassLoader.loadLibrary0 (Unknown source) at java.lang.ClassLoader.loadLibrary (Unknown source) at java.lang.Runtime.load0 (Unknown source) at java.lang.System.load (Unknown source) at com.ankur.FirstJNI Example (FirstJNIExample.java: 9) Could not find main class: com.ankur.FirstJNIExample. The program will be closed.

I don't know for which all dlls my FirstJNIExample.dll depends.

I saw in Dependency Walker that my dll depends on the following DLLs: msvcr90.dll kernel32.dll and this kernel32.dll depends on: ntdll.dll

I also see an error in Dependency Walker for msvcr90.dll that the system cannot find the file specified.

This DLL is present on my system at this location: D: \ Program Files \ Microsoft Visual Studio 9.0 \ VC \ redist \ x86 \ Microsoft.VC90.CRT

When I thought about loading it myself in code like:

enter code here

      

System.load ("D: / Program Files / Microsoft Visual Studio 9.0 / VC / redist / x86 / Microsoft.VC90.CRT / msvcr90.dll")

System.load ("d: /examples/FirstJNIExample.dll");

I am getting windows error:


Microsoft Visual C ++ Runtime Library

Runtime error!

Program: C: \ Windows \ system32 \ java.exe

R6034

The application tried to load the C runtime library incorrectly.
Please contact support for more information.


OK

And this is the exception:

Exception in the "main" thread java.lang.UnsatisfiedLinkError: D: \ Program Files \ Micr osoft Visual Studio 9.0 \ VC \ redist \ x86 \ Microsoft.VC90.CRT \ msvcr90.dll: The dynamic link library (DLL) initialization routine in java.lang.ClassLoader $ NativeLibrary.load (Native Method) at java.lang.ClassLoader.loadLibrary0 (Unknown Source) at java.lang.ClassLoader.loadLibrary (Unknown Source) at java.lang.Runtime.load0 (Unknown Source) at java.lang.System.load (Unknown source) at com.ankur.FirstJNI Example (FirstJNIExample.java:10) Could not find main class: com.ankur.FirstJNIExample. The program will be closed.

I was just lost. So many questions: Why is my dll dependent on msvcr90.dll? How do I load this DLL?

I've never worked with a dll before.

+2


source to share


1 answer


It looks like you need a manifest or switch to static binding and / or manipulate PATH.

Almost any C ++ code you write on Windows will use the MSVC runtime. By default, this code is linked dynamically. If you use dumpbin / import in your JNI DLL, you will see the dependency.



The JRE is calling LoadLibrary, not LoadLibraryEx, so it is not good enough to have the dependency sit next to the JNI library. You must have a directory containing the MSVC runtime DLL in your PATH. Or you need to link it statically, but I'm not sure if this is possible with MSVC90. Or you need to manifest it.

+4


source







All Articles