How to Compile JNI program on windows/cygwin

S

Suresh

Hi,

I am working on windows xp, java(jdk1.5.0_06) installed on it. I dont
have developer studio. i installed cygwin and gcc, make working fine on
cygwin.

now i would like to compile a simple JNI program. but i am getting so
many errors like this.

JavaSide.java:
public class JavaSide {
public native void sayHello();

static {
System.loadLibrary("NativeSideImpl");
}

public static void main(String[] args) {
JavaSide app = new JavaSide();
app.sayHello();
}
}
------------------------------------------
NativeSideImpl.cpp:

#include <stdio.h>
#include "JavaSide.h"

JNIEXPORT void JNICALL Java_JavaSide_sayHello
(JNIEnv *env, jobject obj)
{
printf("Hello Native World!");
}
---------------------------------------------

steps i followed is:
1) javac JavaSide.java
2) javah JavaSide
3) gcc -I /cygdrive/c/Program Files/Java/jdk1.5.0_06/include/ -I
/cygdrive/c/Program Files/Java/jdk1.5.0_06/include/win32
NativeSideImpl.cpp

Now i am getting so may errors like this

In file included from /cygdrive/c/Program
Files/Java/jdk1.5.0_06/include/jni.h:27,
from JavaSide.h:2,
from NativeSideImpl.cpp:2:
/cygdrive/c/Program Files/Java/jdk1.5.0_06/include/win32/jni_md.h:16:
error: `__int64' does not name a type
In file included from JavaSide.h:2,
from NativeSideImpl.cpp:2:
/cygdrive/c/Program Files/Java/jdk1.5.0_06/include/jni.h:108: error:
`jlong' does not name a type
/cygdrive/c/Program Files/Java/jdk1.5.0_06/include/jni.h:307: error:
expected identifier before '*' token
/cygdrive/c/Program Files/Java/jdk1.5.0_06/include/jni.h:308: error:
ISO C++ forbids declaration of `jlong' with no type
/cygdrive/c/Program Files/Java/jdk1.5.0_06/include/jni.h:308: error:
`jlong' declared as function returning a function
/cygdrive/c/Program Files/Java/jdk1.5.0_06/include/jni.h:308: error:
ISO C++ forbids declaration of `CallLongMethod' with no type
/cygdrive/c/Program Files/Java/jdk1.5.0_06/include/jni.h:308: warning:
`__stdcall__' attribute only applies to function types


Can any one please help me in compiling this simple program.

Thanks in advance.
Suresh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top