This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Creating a dll in cygwin for use with jni without -mno-cygwin

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

> 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 example in the

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.


Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]