• Post Reply Bookmark Topic Watch Topic
  • New Topic

JNI example gives UnsatisfiedLinkError

 
slade cox
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have copied and compiled the JNI example given by Sun at http://java.sun.com/docs/books/tutorial/native1.1/stepbystep/index.html. I used gcc on cygwin to compile HelloWorldImp.c. When I run it, I get the following error:



The the current directory is in PATH, so it's not a path issue. The JNIEXPORT appears to be properly defined in jni.h, so it shouldn't be an issue of exporting the function. Any other suggestions?

I'm running a completely updated cygwin on win2k. HelloWorldImp.c is:

 
slade cox
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I feel stupid posting a question and then replying with the solution. But, I found the problem so I might as well post it. Two switches needed to be added to the gcc command.

-Wl,--add-stdcall-alias
This seems to export the function correctly, while the JNIEXPORT seems to do nothing at all. (-Wl,--kill-at seems to work as well. Anyone know what difference it makes beyond a smaller file?)

-mno-cygwin
Without this, java exits abruptly with exit code 128 and no error messages. I presume this is a bug/issue with cygwin.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!