Error in simple JNI project

hi,

I am new to JNI and I am trying a simple HelloWorld project but I am getting the following exception :

Exception in thread"main" java.lang.UnsatisfiedLinkError: displayHelloWorld

at HelloWorld.displayHelloWorld(Native Method)

at HelloWorld.main(HelloWorld.java)

where comes my error from?

[356 byte] By [Isaaka] at [2007-11-26 15:34:52]
# 1
Your error comes from unsatisfied link. Show your code at least.
Michael.Nazarov@sun.coma at 2007-7-8 21:52:18 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

I am trying to implement the example from tutorial:

class HelloWorld {

public native void displayHelloWorld();

static {

System.loadLibrary("hello");

}

public static void main(String[] args) {

new HelloWorld().displayHelloWorld();

}

}

after I am having some dificulties to generate dll where (I think ) are all my difficulties.

cl -Ic:\java\include -Ic:\java\include\win32

-LD HelloWorldImp.c -Fehello.dll

I am putting my java path of my jdk, what path I have to put for cl -Ic and -LD ?

Isaaka at 2007-7-8 21:52:18 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3
Show c-code as well please.
Michael.Nazarov@sun.coma at 2007-7-8 21:52:18 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4

c header

/* DO NOT EDIT THIS FILE - it is machine generated */

#include <jni.h>

/* Header for class HelloWorld */

#ifndef _Included_HelloWorld

#define _Included_HelloWorld

#ifdef __cplusplus

extern "C" {

#endif

/*

* Class:HelloWorld

* Method:displayHelloWorld

* Signature: ()V

*/

JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld

(JNIEnv *, jobject);

#ifdef __cplusplus

}

#endif

#endif

implementation for native

#include <jni.h>

#include "HelloWorld.h"

#include <stdio.h>

JNIEXPORT void JNICALL

Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)

{

printf("Hello world!\n");

return;

}

Isaaka at 2007-7-8 21:52:18 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 5
Looks and works fine for me.Well do you have your dll in same directory with class file?
Michael.Nazarov@sun.coma at 2007-7-8 21:52:18 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 6
can you detail me how you generate dll from command line by above mentioned command? I cannot generate it, so I generate it by Visual C++ 6.0. I think my error comes from there.
Isaaka at 2007-7-8 21:52:18 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 7
cl -ID:\Java\jdk1.6.0\include -ID:\Java\jdk1.6.0\include\win32 "-ID:\Program Files\Microsoft Visual C++ Toolkit 2003\include" -LD HelloWorldImp.c -Fehello.dll /link "/LIBPATH:D:\Program Files\Microsoft Visual C++ Toolkit 2003\lib"Correct paths according yours.
Michael.Nazarov@sun.coma at 2007-7-8 21:52:18 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 8
Michael Thank you very match the error was in lib path
Isaaka at 2007-7-8 21:52:18 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 9
You are welcome :)
Michael.Nazarov@sun.coma at 2007-7-8 21:52:18 > top of Java-index,Java HotSpot Virtual Machine,Specifications...