using Cygwin (-mno-cygwin) to JNI to a 3rd party DLL

Brian Dessent
Tue May 1 20:24:00 GMT 2007

Pete Flugstad wrote:

>   But when I add the 3rd party DLL calls back in (and link against the
> link lib),
> everything links OK, but when I try and run it, I get an error from the JVM:
>            Load Error: myJni.dll: Invalid access to memory location
>       java.lang.UnsatisfiedLinkError: myJni.dll: Invalid access to
> memory location
>         at java.lang.ClassLoader$NativeLibrary.load(Native Method)
>         at java.lang.ClassLoader.loadLibrary0(
>         at java.lang.ClassLoader.loadLibrary(
>         at java.lang.Runtime.loadLibrary0(
>         at java.lang.System.loadLibrary(
>         at com.test.jniTest.main(

You'll have to run this in a debugger to be sure, but I'd start looking
at calling convention clashes, i.e. stdcall vs cdecl.  This should be a
function of the header files and how they declare prototypes.

>   I setup the same C code under MSVC and generate with that, and it works
> just fine.  In looking at the MSVC generated DLL, I see that it's symbol names
> have an underscore '_' on the front of them, while the GCC -mno-cygwin
> generated ones do not.   I don't know that that matters, as when I built without
> the 3rd party DLL, it still works.

The name mangling when using stdcall is rather confusing, see

>   I realize this may not be the right place for this question - it may
> be more GCC
> related than Cygwin related (especially since I'm using -mno-cygwin),
> but I know the
> guys who did a lot work on LD to make this work are here.  I'm maybe hoping
> someone here has seen this before?  Alternatively, what is the right
> place for this
> question - the main GCC mailing list?  Or maybe it's a Sun/JVM question?

This is not the right list.  When using -mno-cygwin you aren't using any
of Cygwin, you're essentially cross compiling to MinGW.  So their
mailing list would probably be the right place to ask.  The gcc list is
*never* the right place to ask anything relating to debugging program
crashes, unless you can actually identify a specific compiler bug (which
it never is, 99.999% of the time.)


Unsubscribe info:
Problem reports:

More information about the Cygwin mailing list