Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JNI Dependent Libraries Not Found  RSS feed

 
Omkar Shetkar
Ranch Hand
Posts: 100
2
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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: 100
2
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • 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: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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: 100
2
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob. I got it working in Linux. Finally I need to implement this in Linux environment.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!