This is the mail archive of the cygwin@cygwin.com 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]

java and C++


I would like to be able to run C code from Java.  I've done this under
Solaris with no problems, but now I'm using cygwin gcc under Windows 2000.
I thought i'd start with the simple example on the Java Sun webpage.
Get stuck making the dll.  Mail errors have to do with jlong in the jni.h
file.  Have put copies of all files, etc, in attachment.

Any help would be greatly appreciated.  tucker
// HelloWorld.java  --compiles into HelloWorld.class

class HelloWorld {
    public native void displayHelloWorld();

    static {
        System.loadLibrary("hello");
    }
    
    public static void main(String[] args) {
        new HelloWorld().displayHelloWorld();
    }
}
=================================
// HelloWorld.h

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>

/* Header for class HelloWorld */

#ifndef _Included_HelloWorld
#define _Included_HelloWorld

#ifdef __cplusplus
extern "C" {
#endif

/*

 * Class:     HelloWorld

 * Method:    displayHelloWorld

 * Signature: ()V

 */

JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld

  (JNIEnv *, jobject);


#ifdef __cplusplus
}
#endif

#endif


=================================================
//HelloWorldImp.h

#if defined(MAKEDLL)
   #  define INTERFACE __declspec(dllexport)
   #elif defined(USEDLL)
   #  define INTERFACE __declspec(dllimport)
   #else
   #  define INTERFACE
   #endif

INTERFACE
JNIEXPORT void JNICALL 
Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj); 

======================================================

// HelloWorldImp.c
#include <jni.h>
#include "HelloWorld.h"
#include <stdio.h>
#include "HelloWorldImp.h"

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

=======================================


maney@PC35 /cygdrive/c/JAVAandC++
$ gcc -DMAKEDLL -Ic:/jdk1.3/include -Ic:/jkd1.3/include/win32 -c HelloWorldImp.
c -o HelloWorldImp.o
In file included from HelloWorldImp.c:1:
HelloWorldImp.h:10: syntax error before `void'
HelloWorldImp.h:11: parse error before `*'
HelloWorldImp.h:11: warning: data definition has no type or storage class
In file included from jni.h:30,
                 from HelloWorldImp.c:2:
jni_md.h:19: parse error before `jlong'
jni_md.h:19: warning: data definition has no type or storage class
In file included from HelloWorldImp.c:2:
jni.h:111: parse error before `jlong'
jni.h:111: warning: no semicolon at end of struct or union
jni.h:115: parse error before `}'
jni.h:115: warning: data definition has no type or storage class
jni.h:258: parse error before `jvalue'
jni.h:273: parse error before `jvalue'
jni.h:280: parse error before `jvalue'
jni.h:287: parse error before `jvalue'
jni.h:294: parse error before `jvalue'
jni.h:301: parse error before `jvalue'
jni.h:308: parse error before `jvalue'
jni.h:310: warning: no semicolon at end of struct or union
jni.h:312: warning: `__stdcall__' attribute directive ignored
jni.h:313: `jlong' declared as function returning a function
jni.h:313: `jlong' redeclared as different kind of symbol
jni_md.h:19: previous declaration of `jlong'
jni.h:313: warning: data definition has no type or storage class
jni.h:314: warning: `__stdcall__' attribute directive ignored
jni.h:315: parse error before `jvalue'
jni.h:315: `jlong' declared as function returning a function
jni.h:315: warning: data definition has no type or storage class
jni.h:322: parse error before `jvalue'
jni.h:329: parse error before `jvalue'
jni.h:336: parse error before `jvalue'
jni.h:345: parse error before `jvalue'
jni.h:354: parse error before `jvalue'
jni.h:363: parse error before `jvalue'
jni.h:372: parse error before `jvalue'
jni.h:381: parse error before `jvalue'
jni.h:390: parse error before `jvalue'
jni.h:392: warning: `__stdcall__' attribute directive ignored
jni.h:393: `jlong' declared as function returning a function
jni.h:393: warning: data definition has no type or storage class
jni.h:394: warning: `__stdcall__' attribute directive ignored
jni.h:396: `jlong' declared as function returning a function
jni.h:396: warning: data definition has no type or storage class
jni.h:397: warning: `__stdcall__' attribute directive ignored
jni.h:399: parse error before `jvalue'
jni.h:399: `jlong' declared as function returning a function
jni.h:399: warning: data definition has no type or storage class
jni.h:408: parse error before `jvalue'
jni.h:417: parse error before `jvalue'
jni.h:426: parse error before `jvalue'
jni.h:443: warning: `__stdcall__' attribute directive ignored
jni.h:444: `jlong' declared as function returning a function
jni.h:444: warning: data definition has no type or storage class
jni.h:463: parse error before `jlong'
jni.h:477: parse error before `jvalue'
jni.h:484: parse error before `jvalue'
jni.h:491: parse error before `jvalue'
jni.h:498: parse error before `jvalue'
jni.h:505: parse error before `jvalue'
jni.h:512: parse error before `jvalue'
jni.h:514: warning: `__stdcall__' attribute directive ignored
jni.h:515: `jlong' declared as function returning a function
jni.h:515: warning: data definition has no type or storage class
jni.h:516: warning: `__stdcall__' attribute directive ignored
jni.h:517: `jlong' declared as function returning a function
jni.h:517: warning: data definition has no type or storage class
jni.h:518: warning: `__stdcall__' attribute directive ignored
jni.h:519: parse error before `jvalue'
jni.h:519: `jlong' declared as function returning a function
jni.h:519: warning: data definition has no type or storage class
jni.h:526: parse error before `jvalue'
jni.h:533: parse error before `jvalue'
jni.h:540: parse error before `jvalue'
jni.h:556: warning: `__stdcall__' attribute directive ignored
jni.h:557: `jlong' declared as function returning a function
jni.h:557: warning: data definition has no type or storage class
jni.h:576: parse error before `jlong'
jni.h:638: parse error before `*'
jni.h:639: warning: data definition has no type or storage class
jni.h:656: parse error before `jlong'
jni.h:673: parse error before `jlong'
jni.h:690: parse error before `jlong'
jni.h:732: parse error before `}'
In file included from HelloWorldImp.c:3:
HelloWorld.h:16: conflicting types for `Java_HelloWorld_displayHelloWorld'
HelloWorldImp.h:11: previous declaration of `Java_HelloWorld_displayHelloWorld'

maney@PC35 /cygdrive/c/JAVAandC++
$
--
Want to unsubscribe from this list?
Check out: http://cygwin.com/ml/#unsubscribe-simple

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