Hi everyone,
First off all:
- Yes, I have searched this forum for "UnsatisfiedLinkError" and found 457(!!!) entries;
- Yes, I've read them all;
- Yes, I did use "javah" to create the header file;
- Yes, I create my HelloWorld class in the default package;
- Yes, I'm shure, the system loads my "Hello.dll".
But it throws the "UnsatisfiedLinkError" nevertheless!
I'm running Windows XP with Java 1.5.0. My IDE is Netbeans 4.0 Beta 2.
The C-compiler is gcc from "http://visual-mingw.sourceforge.net" (gcc 3.2.3).
Here is my .java file:
public class HelloWorld {
public native void displayHelloWorld();
static {
System.loadLibrary("Hello");
}
public HelloWorld() {
}
public static void main(String[] args) {
String lp=System.getProperty("java.library.path");
System.err.println("LP: "+lp);
new HelloWorld().displayHelloWorld();
}
}
This is my header file, created with javah:
/* 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
This is my .c file:
#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>
JNIEXPORT void JNICALL
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj)
{
printf("Hello world!\n");
return;
}
It compiles with 2 warnings about not useage of the parameters "env" and "obj".
This is the output of the command "nm Hello.dll | grep "T _":
61bc1680 T ___CTOR_LIST__
61bc15d0 T ___dllonexit
61bc11e0 T ___do_global_ctors
61bc11b0 T ___do_global_dtors
61bc1160 T ___do_sjlj_init
61bc168c T ___DTOR_LIST__
61bc1240 T ___main
61bc1000 T ___RUNTIME_PSEUDO_RELOC_LIST__
61bc1000 T ___RUNTIME_PSEUDO_RELOC_LIST_END__
61bc1390 T ___w32_sharedptr_initialize
61bc1680 T __CTOR_LIST__
61bc168c T __DTOR_LIST__
61bc1000 T __end__
61bc1600 T __errno
61bc1130 T __onexit
61bc12a0 T __pei386_runtime_relocator
61bc1000 T __RUNTIME_PSEUDO_RELOC_LIST__
61bc1000 T __RUNTIME_PSEUDO_RELOC_LIST_END__
61bc1630 T _abort
61bc1650 T _AddAtomA@4
61bc1100 T _atexit
61bc11a0 T _DllMain@12
61bc1000 T _DllMainCRTStartup@12
61bc1000 T _end
61bc15e0 T _fflush
61bc1640 T _FindAtomA@4
61bc15f0 T _free
61bc1660 T _GetAtomNameA@12
61bc117e T _Java_HelloWorld_displayHelloWorld@8
61bc1610 T _malloc
61bc1620 T _printf
And finally this is the error message I get when running "java HelloWorld":
Exception in thread "main" java.lang.UnsatisfiedLinkError: displayHelloWorld
at HelloWorld.displayHelloWorld(Native Method)
at HelloWorld.main(HelloWorld.java:14)
For me it looks like: The Hello.dll is loaded but the "displayHelloWorld" method is not found.
But why? I can find "T
JavaHelloWorld_displayHelloWorld@8" in the DLL.
Can anyone help me to find out, what's going wrong, please.