This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes JNI - library path - link error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "JNI - library path - link error" Watch "JNI - library path - link error" New topic

JNI - library path - link error

Saidul Islam

Joined: Dec 05, 2000
Posts: 18
Hi everyone-
I am trying to run this simple app that uses a native method. Everthing is created and compiled fine.
I compiled the my .java.
I created the .h
I created my .cpp
I created my .so
So, everything is cool. I run my app like...
java myjavaapp
and it gives me
Exception in thread "main" java.lang.UnsatisfiedLinkError: no dispname in java.library.path
ok so I set my $LD_LIBRARY_PATH and exported it. and I still get the same thing.
what am i missing?

Melissa Aron

Joined: Feb 19, 2001
Posts: 1
I cant really help you, because I am having the same issue as you...but maybe we can work together to figure out the problem. I am trying something pretty similar to what you are doing. What I have found though is that when I create my .cpp, if I use C commands, ie. printf, I compile, and run perfectly. However, if I substitute "cout" in place of the printf, I suddenly go back to the UnsatisfiedLink error.
Could this mean that I for whatever reason am not linking properly to standard C++ libraries? I am including the appropriate header files, and I can run a similar application from command line, just not via my java class... Anybody, HELP!
Saidul Islam

Joined: Dec 05, 2000
Posts: 18
in my case, it doesn't matter what I try, either C (.c) or C++ (.cpp), I still get the same error

Here is my small hello world kind java app
public class DisplayName {
public native void display();
static {
System.out.println("gets here2");
try {
catch (UnsatisfiedLinkError e) {
System.out.println("Error: " + e.getMessage());
} //End of static block
public static void main(String[] args) {
System.out.println("gets here1");
new DisplayName().display();
} //End of my main method
} //End of DisplayName class

Here is my DisplayName.h
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class DisplayName */
#ifndef _Included_DisplayName
#define _Included_DisplayName
#ifdef __cplusplus
extern "C" {
* Class: DisplayName
* Method: display
* Signature: ()V
JNIEXPORT void JNICALL Java_DisplayName_display
(JNIEnv *, jobject);
#ifdef __cplusplus
Here is my dispname.cpp
#include <jni.h>
#include "DisplayName.h"
#include <iostream.h>
JNIEXPORT void JNICALL Java_DisplayName_display(JNIEnv *env, jobject obj)
cout << "Hello Saidul!";<br /> return;<br /> }<br /> --------------------------------------------------------------<br /> this is how I am trying to make the .so<br /> sislam@w2/javaexpm/jni> CC -G -I/usr/java1.2/include -I/usr/java1.2/include/solaris dispname.cpp -o<br /> <br /> it creates the fine<br /> when I run<br /> sislam@w2/javaexpm/jni> java DisplayName
i get the following
gets here2
Error: no in java.library.path
gets here1
Exception in thread "main" java.lang.UnsatisfiedLinkError: display
at DisplayName.main(
Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
One more addition to the JNI victims list. I get the same error. But I dont use any C++ specific calls. I replaced te System.loadLibrary("my.dll") function with the System.load("absPath\my.dll") and it worked. But the Exception is now thrown when I try to access a native method.
Any solutions found?
Madhusudhan Srinivasan

Joined: Jan 07, 2003
Posts: 1
One possible solution. I think you dont need to specify .so or .dll in the System.loadLibrary method call. i.e, all you have to do in the static block is

And also, your java code will remain independent of the platform.
Hope this helps.
Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
yeah! I have done that. The actual problem in accessing the native method was due to copy /paste. This code was present in the implementation file.
So, it generated the lib but without any functions.
Anyway, thanks for ur suggestion madhu!
I agree. Here's the link:
subject: JNI - library path - link error
Similar Threads
Problem in compilation with classpath of jar file
compiled java file for jsp
NoClassDefFoundError in Servlets
jdbc connection !!
How to Change these Folder Security Permission?