• 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

JNI (UnsatisfiedLinkError)

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 691
Mac
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DLL is not called properly.
 
ronnie lee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Popeye has his spinach. I have this 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