Subject: Java Native Interface with gnu-win32
From: [email-masked] ("R. Wester")

4 Apr 1997 14:31:41 -0800
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Reply-To: [email-masked]
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7BIT
X-ENV: (mailgw1.fhg.de) [email-masked] -> [email-masked]
Comments: Authenticated sender is <[email-masked]>
Original-To: [email-masked]
X-Mailer: Pegasus Mail for Win32 (v2.42a)
Original-Sender: [email-masked]

Hi,

I tried to build a dll for using it from inside a Java class via
the Java Native Interface. During compilation of the sample program
from SUN's Java Tutorial
(http://www.javasoft.com:80/nav/read/Tutorial/native1.1/stepbystep/ind
ex.html):

    #include <jni.h>
    #include "HelloWorld.h"
    #include <stdio.h>

    JNIEXPORT void JNICALL 
    Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj) 
 {
  printf("Hello world!\n");
     return;
 }

with gnu-win32 g++ I get a lot of error messages. Compiling with MVC++
works.

In the Java (SUN JDK 1.1) include file jni.h there are statements
like:

 jint (JNICALL *GetVersion)(JNIEnv *env); 

JNICALL is defined in win32/jni_md.h:

 #define JNICALL __stdcall

Compiling the small sample code:

 int __attribute__ ((stdcall)) (*g)(int i);
 int __stdcall (*f)(int i);
 int __cdecl (*h)(int i);

 int (__attribute__ ((stdcall)) *g)(int i);
 int (__stdcall *f)(int i);
 int (__cdecl *h)(int i);

with MVC++ and gnu-win32 g++ produces the following error messages:

compile with MVC++ :
....
test.cpp
C:\Java11\classes\dll\test.cpp(1) : error C2065: 'stdcall' : undeclared identifier 
C:\Java11\classes\dll\test.cpp(1) : error  C2501: '__attribute__' : missing decl-specifiers
C:\Java11\classes\dll\test.cpp(1) : error C2143: syntax error :  missing ';' before '(' 
C:\Java11\classes\dll\test.cpp(1) : error C2059: syntax error : ')'
C:\Java11\classes\dll\test.cpp(1) : error C2143: syntax error : missing ')' before ';'
C:\Java11\classes\dll\test.cpp(1) : error C2501: 'g' : missing decl-specifiers 
C:\Java11\classes\dll\test.cpp(2) : error C2059: syntax error : '(' 
C:\Java11\classes\dll\test.cpp(3) : error C2059: syntax error : '(' 
C:\Java11\classes\dll\test.cpp(5) : error C2199: syntax error : found 'int (' at global scope 
       (was a declaration intended?) Error executing cl.exe. test.obj - 9 error(s), 0 warning(s)

compile with gnu-win32 :

g++ -c test.cpp
test.cpp:5: syntax error befor '__attribute__'
test.cpp:6: syntax error befor '__attribute__'
test.cpp:7: syntax error befor '__attribute__'

So MVC++ and gnu-win32 seem not to be compatible at this point:

 gnu_win32 : int __stdcall (*f)(int i);
 MVC : 	    int (__stdcall *f)(int i);

I would like to use gnu-win32 for building the dll's but it does'nt
work as it is. I would be very appreciative for any help (including
the statement that there is no work around for that problem).

-- Rolf

eMail: [email-masked]
------------------------------------------------------------
# Rolf Wester
# Fraunhofer Institut f. Lasertechnik 
# Steinbachstr. 15, D-52074 Aachen, Germany.
# Tel: + 49 (0) 241 8906 0, Fax: +49 (0) 241 8906 121
# EMail: [email-masked], WWW: http://www.ilt.fhg.de
-
For help on using this list, send a message to
"[email-masked]" with one line of text: "help".