• Post Reply Bookmark Topic Watch Topic
  • New Topic

JNI (UnsatisfiedLinkError)  RSS feed

 
ronnie lee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trying a simple hello program using C n Java. I get the Exception UnsatisfiedLinkError. What may be the reason for this? The dll file is in the same directory.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

There are many possible reasons. One trivial one is that the DLL needs to be on the PATH, or named in the java.lib.path system property. Another is that you've named the native method incorrectly, or you haven't exported it from the DLL. Here is a simple step-by-step recipe for writing your first JNI program.
 
Jignesh Patel
Ranch Hand
Posts: 626
Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DLL is not called properly.
 
ronnie lee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the welcome note Ernest.

Went through the doc. Now how do i convert a c program to a dll. Uptil compilation of the c program all is fine. The java file is compiled and the header file generated.

I am using DevC++ 4.0. How do i name the dll in the java.lib.path??

Too many questions right but i m all muddled up n need help.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16007
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to compile a C program as a DLL: You need to look that up in the documentation of your compiler (DevC++, as you say).

How to make sure the DLL is in the Java library path: Set the java.library.path system variable on the command line while starting your application, like this:



(Note: it's java.library.path, not java.lib.path as Ernest suggested).
[ September 01, 2005: Message edited by: Jesper de Jong ]
 
ronnie lee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the help.
Finally got it working using Microsoft VC++.
Now can go further and try other programs as well...
Regards
Ronnie.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!