On Fri, 20 May 2005 01:07:44 GMT, cppaddict wrote:
> My java method (part of the Engine class in the package blackjack)
> looks like:
>
> public native void init(String windowTitle);
>
> My C JNI method stub look like:
>
> JNIEXPORT void JNICALL Java_blackjack_Engine_init(JNIEnv *, jobject,
> jstring);
>
> The DLL compiles without error, and is being loaded without error
> (in a static block). What else could be causing the unsatisifed link
> error?
There are two things that cause UnsatisfiedLinkError. One is when
System.loadLibrary() fails to load the library, the other is when the
JVM fails to find a specific method in the library. The text of the
error message itself will indicate which is the case, but you've
already indicated that the library loads ok.
The JVM will fail to find a method in the library for various reasons,
but essentially they all point to the same thing: that a method with
the specified name was not found. Realize that the compiler itself
sometimes does things with the symbol names unless you tell it not to,
and this will prevent the JVM from finding the method, even though
you've named them correctly.
Examine the library contents, for example with objdump or nm (on unix)
or dumpbin or quickview (on windows) to see what's there.
Here are some things that can cause the symbols in the library to be
different from your source code:
- you are compiling with a C++ compiler, and it has mangled the symbol
names because you failed to declare your native methods with extern
"C". If you included the header file generated by javah (which you
should), and your signatures *exactly* match those in the header
file generated by javah (which they should), then then this has
already been done for you. If that isn't the case, why not?
- your compiler has added extra information to the symbol names such
as @8 or @12. There should be a compiler option to prevent that (for
gcc, try -Wl,--kill-at).
/gordon
--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
|