X-Spam-Check-By: sourceware.org Message-ID: <84d4a6d50705011311m24edaf7dw73f40a72bc4a750e@mail.gmail.com> Date: Tue, 1 May 2007 15:11:56 -0500 From: "Pete Flugstad" To: cygwin AT cygwin DOT com Subject: using Cygwin (-mno-cygwin) to JNI to a 3rd party DLL MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Hello, 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(ClassLoader.java:1751) at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1676) at java.lang.Runtime.loadLibrary0(Runtime.java:822) at java.lang.System.loadLibrary(System.java:993) at com.test.jniTest.main(miniAce.java:33) 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 system.library.path). 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? Thanks, Pete -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/