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: JNI loading dlls which link to cygwin1.dll

Have a look at the thread that starts here:

If that doesn't help you, please report back :)

(In short, that thread lead to the conclusion that there was a problem with the calling convention used. Your linker flag to add stdcall versions of the functions is not too far off the final result).



Andrew Hinton wrote:

I have been attempting to port a large program from
Linux to Windows using Cygwin.  The program is written
in Java, C and C++; using the JNI to link them

I have successfully compiled and linked all of the C
and C++ code using Cygwin, and successfully executed a
test program written in C++.

The following illustrates the compiler flags I was

g++ -c -D__int64="long long" ###includes### *.cc
gcc -Wl,--add-stdcall -shared -o ~/prism/lib/file.dll
*.o -L ~/prism/lib -lutil -lepd

The problem comes when the JNI tries to load the
shared dlls in the loadLibrary() method. The JNI
appears to be able to find the libraries, as no
UnsatisfiedLinkError is reported; however, the
execution halts, giving no output.

It appears that JNI has problems with cygwin1.dll,
because I have had no JNI problems with dlls not
created using Cygwin.

After searching the Internet and this mailing list,
most sources seem to point out that I should use the
-mno-cygwin compiler flag.  This appears to remove the
need for the cygwin1.dll at runtime.  However, this
results in compile errors.  For example:

$ gcc -c -D__int64="long long" -I../mnemosyne/ *.c

This works fine … but this doesn’t:

$ gcc -mno-cygwin -c -D__int64="long long"
-I../mnemosyne/ *.c
datalimit.c:17:26: sys/resource.h: No such file or
pipefork.c:12:22: sys/wait.h: No such file or
test-res.c:5: error: syntax error before '(' token
test-res.c:9: error: syntax error before '{' token
test-res.c:13: error: conflicting types for `prog'
test-res.c:11: error: previous declaration of `prog'
test-res.c:13: warning: data definition has no type or
storage class
test-res.c:14: error: syntax error before "if"
test-res.c:16: error: syntax error before numeric
test-res.c:16: error: conflicting types for `exit'
/usr/i686-pc-mingw32/include/stdlib.h:357: error:
previous declaration of `exit'
test-res.c:16: warning: data definition has no type or
storage class
test-res.c:18: error: syntax error before string
test-res.c:18: error: conflicting types for
util.h:240: error: previous declaration of
test-res.c:18: warning: data definition has no type or
storage class
test-res.c:20: error: initializer element is not
test-res.c:20: warning: data definition has no type or
storage class
test-res.c:21: error: syntax error before "void"
test-res.c:25: error: syntax error before '!=' token
test-res.c:30: error: redefinition of `i'
test-res.c:20: error: `i' previously defined here
test-res.c:30: warning: data definition has no type or
storage class
test-res.c:31: error: syntax error before "for"
test-res.c:31: error: syntax error before '!=' token

The problem seems to be that a lot of the program uses
routines that (I think) are not part of the windows
API, specifically the following headers are used:


I have searched the Internet, the Cygwin manual and
Cygwin’s FAQ and I have found nothing that explains
the problem with JNI and cygwin1.dll.  Could anyone
either point me in the right direction or say whether
I am doing anything wrong.  Or does anyone know if
there is a way to make this work without the need for
the cygwin1.dll?

I have attached the cygcheck file.


Andrew Hinton

Unsubscribe info:
Problem reports:

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