• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JNI Dependent Libraries Not Found

 
Ranch Hand
Posts: 104
2
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am newbie to JNI API. I am trying to do a HelloWorld program using it. I have written a Java program (Test.java) containing a native method. The native method is implemented in 'C'(Test.c) to print a string. On these files

1. I compiled Test.java. - javac
2. Generated a header file. - javah
3. Taken the method signature form Test.h an put it into Test.c
4. Using cl command generated a test.dll file
5. Tried to run it using java Test but getting the following error

Exception in thread "main" java.lang.UnsatisfiedLinkError: D:\JNITest\test.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.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at Test.<clinit>(Test.java:7)

All of my files are in a single folder.

Will be waiting for your replies...

Thanks in advance

Regards,
Omkar V S
 
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems it can find your test.dll, it just can't find one or more of the libraries test.dll depends on.

What libraries are you calling from Test.c?
 
Omkar Shetkar
Ranch Hand
Posts: 104
2
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My 'C' program is

#include <jni.h>
#include "Test.h"
#include <stdio.h>


JNIEXPORT void JNICALL Java_Test_getValue
(JNIEnv *e, jobject obj)
{
printf("Hello World!");
}


Command used to generate dll:

D:\JNITest\Test\Test>cl -IC:\Progra~1\Java\jdk1.5.0_06\include\ -IC:\Progra~1\Jav
a\jdk1.5.0_06\include\win32\
-MD -LD Test.c -Fetest.dll


Regards,
Omkar V S
 
Rob Spoor
Sheriff
Posts: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not familiar with CL, but are you sure you are compiling it as a DLL? With gcc (from MinGW ) I have to specify this explicitly with the "-shared" flag.
 
Omkar Shetkar
Ranch Hand
Posts: 104
2
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob. I got it working in Linux. Finally I need to implement this in Linux environment.
 
It means our mission is in jeapordy! Quick, read 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