> I am learning to use JNI by following the walkthrough contained here;
>
[quoted text clipped - 21 lines]
> I am suspicious of the "V" at the end of the Hello.print() line of the
> exception message.
The "V" should be OK. It is probably the way how the "void" return-type is
displayed.
> Does anyone have an idea why this is happening?
The C-function Java_Hello_print is missing in your DLL (or it is not
exported with "JNIEXPORT").
I'm familiar with Microsoft's compiler/linker, but not with Cygwin's.
That said, I would check these:
(*) Did you run javah on your "Hello" class (after your renaming
from "HelloWorld" to "Hello")?
(*) Do you see
JNIEXPORT void JNICALL Java_Hello_print(JNIEnv *, jobject);
in your "Hello.h" file?
(*) Do you include "Hello.h" from your "Hello.c" file?
(*) Do you have the C function
Java_Hello_print(JNIEnv *env, jobject obj) {...}
in your "Hello.c" file?

Signature
Thomas
Thomas Fritsch - 13 May 2007 01:40 GMT
[...]
>>gcc -mno-cygwin -I"${JAVA_PATH}/include" -I"${JAVA_PATH}/include/
>>win32" -W1,--add-stdcall-alias -shared -o Hello.dll Hello.c
[...]
>>$> java Hello
>>Exception in thread "main" java.lang.UnsatisfiedLinkError:
>>Hello.print()V
>> at Hello.print(Native Method)
>> at Hello.main(Hello.java:25)
[...]
> I'm familiar with Microsoft's compiler/linker, but not with Cygwin's.
> That said, I would check these:
[quoted text clipped - 7 lines]
> Java_Hello_print(JNIEnv *env, jobject obj) {...}
> in your "Hello.c" file?
One further check:
(*) Did you load your "Hello.dll" from your Java side? Is there
static { System.loadLibrary("Hello"); }
in your "Hello.java"?

Signature
Thomas
johnmmcparland - 14 May 2007 08:48 GMT
> [...]
> >>gcc -mno-cygwin -I"${JAVA_PATH}/include" -I"${JAVA_PATH}/include/
[quoted text clipped - 25 lines]
> --
> Thomas
Hi Thomas,
thanks for replying. I can confirm that;
1. ran javah on the Hello class to create Hello.h
2. I did see JNIEXPORT void JNICALL Java_Hello_print(JNIEnv *,
jobject); in the Hello.h file (see below);
// extract from Hello.h
#include <jni.h>
extern "C" {
JNIEXPORT void JNICALL Java_Hello_print
(JNIEnv *, jobject);
}
3. Included Hello.h in the Hello.c file (see below);
// extract from Hello.c
#include <jni.h>
#include <stdio.h>
#include "Hello.h"
JNIEXPORT void JNICALL
Java_Hello_print(JNIEnv *env, jobject obj)
{
printf("Hello world!\n");
return;
}
4. I have the Java_Hello_print function in Hello.c (see above).
5. I do load the Hello.dll from the Java side (see below);
// extract of Hello.java
static
{
System.loadLibrary("Hello");
}
6. Despite all of this I still get the error that I originally posted.
Any ideas?
John
Gordon Beaton - 14 May 2007 09:00 GMT
> 4. I have the Java_Hello_print function in Hello.c (see above).
It is apparent from your original post that System.loadLibrary() is
not the culprit. That means that the correct symbol was not found in
the DLL.
Check that the *DLL* contains a symbol with exactly that name, i.e.
that the compiler has not modified the symbol name in any way with
suffixes or similar.
Note the link option should start with -Wl ("ell"), not -W1 (one) as
in your earlier post. I would have expected an error from that.
Is there a package declaration in Hello.java?
/gordon
--
johnmmcparland - 14 May 2007 10:05 GMT
> > 4. I have the Java_Hello_print function in Hello.c (see above).
>
[quoted text clipped - 14 lines]
>
> --
Gordon,
Thanks for your reply.
In your post you said;
> Note the link option should start with -Wl ("ell"), not -W1 (one) as
> in your earlier post. I would have expected an error from that.
Changing 1 (one) to l (ell) worked fixed the problem I was having.
You'd think that we could type our posts in courier new font instead
of arial, that might help matters.
Out of interest, there is no package declaration in Hello.java. When
I put it into a package and modified my compilation / build / linking
as necessary everything worked fine.
Thanks,
John
Gordon Beaton - 14 May 2007 11:55 GMT
> Changing 1 (one) to l (ell) worked fixed the problem I was having.
> You'd think that we could type our posts in courier new font instead
> of arial, that might help matters.
Glad that fixed it for you. I had no problem seeing the difference
between the characters. I read news with slrn in an xterm with a
default fixed font on Linux.
At any rate this just shows the value of cutting and pasting exact
commands and messages directly into your post as you did here.
/gordon
--