• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

UnsatisfiedLinkError in my first JNI program

 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I created a program which uses JNI. I compiled it, generated header file, created a corresponding C program, and created dll for it.
Now I am placing the dll in the folder where my Java program is e.g. my class com.ankur.FirstJNIExample is in d:\examples folder so I am placing this dll into d:\examples folder.

But when I run it I get following exception:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no FirstJNIExample.dll in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.ankur.FirstJNIExample.<clinit>(FirstJNIExample.java:8)
Could not find the main class: com.ankur.FirstJNIExample. Program will exit.

I read here that if you place your dll in same folder then you should be okay. Why it's not picking up my dll then?

Now to get going, I changed my code to this:


It doesn't give above exception as it finds the dll now. But now I am running into another exception:

Exception in thread "main" java.lang.UnsatisfiedLinkError: D:\examples\FirstJNIExample.dll: Can't find dependent libraries
at 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.FirstJNIExample.<clinit>(FirstJNIExample.java:9)
Could not find the main class: com.ankur.FirstJNIExample. Program will exit.

I don't know which all dlls my FirstJNIExample.dll is dependent on. How can I know that? The dll file is unreadable in textpad.

I am not doing much in C program either:


What can be the issue?

Thanks.
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I saw in Dependency Walker that my dll is dependent on following dlls:
msvcr90.dll
kernel32.dll
and this kernel32.dll is dependent on:
ntdll.dll

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

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

When I thought of loading it on my own in code like this:
view plaincopy to clipboardprint?



I get a windows error:



And this exception:

Exception in thread "main" java.lang.UnsatisfiedLinkError: D:\Program Files\Micr
osoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\msvcr90.dll: A dynamiclink library (DLL) initialization routine failed
at 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.FirstJNIExample.<clinit>(FirstJNIExample.java:10)
Could not find the main class: com.ankur.FirstJNIExample. Program will exit.

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

I never worked with dlls before.
 
pie. tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic