Mail Archives: cygwin/1998/09/22/07:59:14
This is a multi-part message in MIME format.
--------------34D05A37FC18318E3F94F764
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
FAQ Maintainers: Please add this info to your sites.
_________________________________________________________________
Subject: More Java JNI with GNU-WIN32 gcc
Date: Tue, 30 Jun 1998 14:05:03 -0400
From: Andrew Mickish <mickish AT CMU DOT EDU>
To: gnu-win32 AT cygnus DOT com
Here are a few more issues that came up when trying to compile
a JNI DLL with gcc.
* There are two different problems that could cause Unsatisfied
link errors. One is if the DLL is not found, and the other is
if the DLL is found but is unreadable or the specific function
cannot be found in it. These problems are distinguishable by
the stack trace that you get below the "Unsatisfied link error,"
and also by testing for changes in behavior when you run Java
after deliberately deleting the DLL or deliberately renaming
some arbitrary text file to be your DLL.
* The directory containing the DLL ought to be in your PATH.
The recommended way to set your path is to change it with the
System control panel and open a new window. The cygnus.bat
file munges the path a little itself, so my own path ends up
looking like this:
bash-2.01$ echo $PATH
/Cygnus/B19/H-i386-cygwin32/bin:/WINNT/system32:/WINNT:/utils:/enscript://E/jdk1.1.5/bin://E/java/HelloWorld
* I had to hand-edit the DEF file and put in an alias for the
exported function. Without the alias, it seems that Cygnus is
exporting the mangled name of the function with its offset
("...@8") and Java is looking for an unmangled name.
My DEF file looks like this:
bash-2.01$ cat hello.def
EXPORTS
Java_HelloWorld_displayHelloWorld=Java_HelloWorld_displayHelloWorld AT 8dll_entry@12
Please let me know if any of this has been helpful.
--Andrew Mickish
mickish AT cmu DOT edu
__________________________________________________________________
Subject: Java JNI with GNU-WIN32 gcc
Date: Thu, 11 Jun 1998 19:48:11 -0400
From: Andrew Mickish <mickish AT CMU DOT EDU>
To: gnu-win32 AT cygnus DOT com
> With significant help from Bill Pringlemeir, I figured out how to
> compile Sun's JNI tutorial HelloWorld example under GNU-WIN32 with
> gcc. I will keep a ZIP file of the gcc-compatible code at
> http://www.andrew.cmu.edu/~am2q/HelloWorld.zip for future reference.
>
> Please add this information to the GNU-WIN32 documentation and FAQ.
> As of version 19.1, it is significantly more complicated to compile
> a Java-compatible DLL under gcc than under Microsoft Visual C++.
> Even printf() does not work in a gcc-compiled DLL, even thoough it
> works fine with VC++. Will this be changing with future releases
> of GNU-WIN32?
>
> Here are a few hints for how to compile a trivial JNI-compaible DLL
> with gcc:
>
> 1) You need init.cc, an element of building relocatable DLLs
>
> 2) There is a complicated linking procedure involving ld and
> intermediate files:
>
> ld --base-file hello.base --dll -o hello.dll HelloWorldImp.o
> init.o $(LIB) -e _dll_entry AT 12
> dlltool --as=as --dllname hello.dll --def hello.def
> --base-file hello.base --output-exp hello.exp
> ld --base-file hello.base hello.exp --dll -o hello.dll
> HelloWorldImp.o init.o $(LIB) -e _dll_entry AT 12
> dlltool --as=as --dllname hello.dll --def hello.def --base-file
> hello.base --output-exp hello.exp
> ld hello.exp --dll -o hello.dll HelloWorldImp.o init.o $(LIB)
> -e _dll_entry AT 12
>
> 3) Printf will not work here. Use a Windows dialog box or
> call back into Java to invoke System.out.println():
>
> void jprintf (JNIEnv *env, char* str) {
>
> jstring jstr = (*env)->NewStringUTF(env, str);
> jclass System_class = (*env)->FindClass(env,
> "java/lang/System");
> jfieldID fid_out = (*env)->GetStaticFieldID(
> env, System_class, "out",
> "Ljava/io/PrintStream;");
> jobject out = (*env)->GetStaticObjectField(
> env, System_class, fid_out);
> jclass PrintStream_class = (*env)->FindClass(env,
> "java/io/PrintStream");
> jmethodID mid_println = (*env)->GetMethodID(env,
> PrintStream_class,
> "println",
> (Ljava/lang/String;)V");
> if (mid_println == 0) {
> exit(1);
> }
> (*env)->CallVoidMethod(env, out, mid_println, jstr);
> }
>
>
> JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld(
> JNIEnv *env, jobject obj)
> {
> (void)env; (void)obj;
> MessageBoxA(NULL,"Hello Jupiter!", "Hello world!", 0);
> jprintf(env, "Hello Uranus!\n");
> return;
> }
>
>
> A collection of files that implement Sun's JNI HelloWorld example
> may be found at http://www.andrew.cmu.edu/~am2q/HelloWorld.zip
>
> --Andrew Mickish
> mickish AT cmu DOT edu
>
--------------34D05A37FC18318E3F94F764
Content-Type: message/rfc822; name="nsmailG1.TMP"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="nsmailG1.TMP"
Return-Path: <owner-gnu-win32 AT cygnus DOT com>
Received: from po2.andrew.cmu.edu (PO2.ANDREW.CMU.EDU [128.2.10.102]) by mail1.andrew.cmu.edu (8.8.5/8.8.2) with ESMTP id GAA25864 for <am2q+@MAIL1.ANDREW.cmu.edu>; Fri, 12 Jun 1998 06:45:42 -0400 (EDT)
Received: (from daemon AT localhost) by po2.andrew.cmu.edu (8.8.5/8.8.2) id GAA01192 for am2q+@MAIL1.ANDREW.CMU.EDU; Fri, 12 Jun 1998 06:37:08 -0400 (EDT)
Received: via switchmail for am2q+@andrew.cmu.edu; Fri, 12 Jun 1998 06:37:08 -0400 (EDT)
Received: from cmu2.cs.cmu.edu (CMU2.CS.CMU.EDU [128.2.206.46]) by po2.andrew.cmu.edu (8.8.5/8.8.2) with ESMTP id GAA01187; Fri, 12 Jun 1998 06:37:06 -0400 (EDT)
Received: (from daemon AT localhost)
by cmu2.cs.cmu.edu (8.8.5/8.8.5) id GAA21111;
Fri, 12 Jun 1998 06:37:05 -0400 (EDT)
Received: via localmail; Fri, 12 Jun 1998 06:37:04 -0400 (EDT)
Received: from cygnus.com (runyon.cygnus.com [205.180.230.5])
by cmu2.cs.cmu.edu (8.8.5/8.8.5) with ESMTP id GAA21107;
Fri, 12 Jun 1998 06:37:03 -0400 (EDT)
Received: (from majordom AT localhost)
by runyon.cygnus.com (8.8.7-cygnus/8.8.7) id QAA28662;
Thu, 11 Jun 1998 16:49:00 -0700 (PDT)
Received: from mail6.bellatlantic.net (mail6.bellatlantic.net [151.201.0.38])
by runyon.cygnus.com (8.8.7-cygnus/8.8.7) with ESMTP id QAA28648
for <gnu-win32 AT cygnus DOT com>; Thu, 11 Jun 1998 16:48:57 -0700 (PDT)
Received: from cmu.edu (client201-118-4.bellatlantic.net [151.201.118.4])
by mail6.bellatlantic.net (8.8.5/8.8.5) with ESMTP
id SAA26371 for <gnu-win32 AT cygnus DOT com>; Thu, 11 Jun 1998 18:48:51 -0500 (EST)
Message-ID: <35806CBB DOT 7ACABDDD AT cmu DOT edu>
Date: Thu, 11 Jun 1998 19:48:11 -0400
From: Andrew Mickish <mickish AT CMU DOT EDU>
X-Mailer: Mozilla 4.04 [en] (WinNT; U)
MIME-Version: 1.0
To: gnu-win32 AT cygnus DOT com
Subject: Java JNI with GNU-WIN32 gcc
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Sender: owner-gnu-win32 AT cygnus DOT com
Precedence: bulk
With significant help from Bill Pringlemeir, I figured out how to compile
Sun's JNI tutorial HelloWorld example under GNU-WIN32 with gcc. I will keep a
ZIP file of the gcc-compatible code at
http://www.andrew.cmu.edu/~am2q/HelloWorld.zip for future reference.
Please add this information to the GNU-WIN32 documentation and FAQ. As of
version 19.1, it is significantly more complicated to compile a
Java-compatible DLL under gcc than under Microsoft Visual C++. Even printf()
does not work in a gcc-compiled DLL, even thoough it works fine with VC++.
Will this be changing with future releases of GNU-WIN32?
Here are a few hints for how to compile a trivial JNI-compaible DLL with gcc:
1) You need init.cc, an element of building relocatable DLLs
2) There is a complicated linking procedure involving ld and intermediate
files:
ld --base-file hello.base --dll -o hello.dll HelloWorldImp.o init.o
$(LIB) -e _dll_entry AT 12
dlltool --as=as --dllname hello.dll --def hello.def --base-file
hello.base --output-exp hello.exp
ld --base-file hello.base hello.exp --dll -o hello.dll HelloWorldImp.o
init.o $(LIB) -e _dll_entry AT 12
dlltool --as=as --dllname hello.dll --def hello.def --base-file
hello.base --output-exp hello.exp
ld hello.exp --dll -o hello.dll HelloWorldImp.o init.o $(LIB) -e
_dll_entry AT 12
3) Printf will not work here. Use a Windows dialog box or call back into
Java to invoke
System.out.println():
void jprintf (JNIEnv *env, char* str) {
jstring jstr = (*env)->NewStringUTF(env, str);
jclass System_class = (*env)->FindClass(env, "java/lang/System");
jfieldID fid_out = (*env)->GetStaticFieldID(env, System_class, "out",
"Ljava/io/PrintStream;");
jobject out = (*env)->GetStaticObjectField(env, System_class, fid_out);
jclass PrintStream_class = (*env)->FindClass(env,
"java/io/PrintStream");
jmethodID mid_println = (*env)->GetMethodID(env, PrintStream_class,
"println", "(Ljava/lang/String;)V");
if (mid_println == 0) {
exit(1);
}
(*env)->CallVoidMethod(env, out, mid_println, jstr);
}
JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld(JNIEnv *env,
jobject obj)
{
(void)env; (void)obj;
MessageBoxA(NULL,"Hello Jupiter!", "Hello world!", 0);
jprintf(env, "Hello Uranus!\n");
return;
}
A collection of files that implement Sun's JNI HelloWorld example may be found
at http://www.andrew.cmu.edu/~am2q/HelloWorld.zip
--Andrew Mickish
mickish AT cmu DOT edu
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".
--------------34D05A37FC18318E3F94F764--
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".
- Raw text -