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

Pete Flugstad
Tue May 1 20:12:00 GMT 2007


  We have a 3rd party Windows DLL that we want to interface with from Java,
obviously using JNI.  The 3rd party DLL provides a link lib to link
against.  It's
a pure C interface (no C++).  I've used the 3rd party DLL just fine for a while
now from MSVC (ver 6), but now we want to call it from Java.

  I've been trying to use Cygwin's GCC with -mno-cygwin to build the JNI
portion - that maps from the JNI call to the actual DLL call -
basically following
the Inonit tutorial (<>).  I've done
this before very successfully (for rebuilding rxtx serial lib) but not
with a 3rd
party DLL in the mix.

  I've tested out all the JNI stuff by commenting out all the calls to
the 3rd party
DLL, and I can get from Java to the native C code just fine.

  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(

  Now, I copied the 3rd party DLL to the same directory as my DLL, and as
I'm running this from (and '.' in in my PATH, and in java's
And I still get the same problem.

  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.

  It seems like maybe there is some problem with the JVM and loading dependent
libs?   But I thought that that was something that Windows did, not
the JVM?  (we're
using Sun's JVM, 1.5.0_11).

  Eventually I would like to use SWIG to automate wrapping the 3rd
party DLL's API,
but I want to get over this hurdle first.

  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?


Unsubscribe info:
Problem reports:

More information about the Cygwin mailing list