X-Spam-Check-By: sourceware.org Message-ID: <46BA2D27.ADF36363@dessent.net> Date: Wed, 08 Aug 2007 13:52:55 -0700 From: Brian Dessent X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U) MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: Creating a dll in cygwin for use with jni without -mno-cygwin References: <12060945 DOT post AT talk DOT nabble DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Reply-To: cygwin AT cygwin DOT com 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 robbincatz wrote: > I have looked at every bit of information on -mno-cygwin, building dlls in > cygwin and jni but nothing has helped although I now believe the problem > lies with the fact that i did not install my libraries for mingw but for > cygwin. Using -mno-cygwin makes a MinGW application/DLL. It is the same as using the MinGW gcc. You can't link together MinGW libraries and Cygwin libraries into the same output, so you would need a MinGW version of every library that your application links to in order to use -mno-cygwin. > If I could create my dll without the -mno-cygwin option I think it would > solve my problem, I have tried with no success to do this. When I try this > everything appears to be fine ( i.e. I receive no error messages ) but when > I run my java code ( which calls the native c code ) it hangs, this happens > even for the most basic "hello world" ap. The problem here is that you're loading the Cygwin1.dll library dynamically, as opposed to linking against it normally. Special steps are required to do this because the Cygwin library has special initialization needs to set up the TLS area at the bottom of the stack for its signal emulation. This is handled automatically by the crt startup objects in a normal Cygwin binary, but when you just call LoadLibrary in a non-Cygwin application you have to handle it yourself. This is covered in the FAQ: . The best reference to how to do this is the cygload.cc example in the testsuite. I have no idea how you'd handle this stack requirement in a java application, other than writing your own initialization procedure that saves a copy of the bottom 4k, initializes Cygwin, and then restores the saved parts. However for this to work (as opposed to the other strategy of making sure that the 4k is actually reserved as early in the initialization process as possible) it means your cleanup/deinit code has to be run before the stack gets unwound down to that part of it that you smashed away. Brian -- 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/