Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

How to Compile JNI program on windows/cygwin

Thread view: 
Suresh - 31 May 2006 21:08 GMT
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
Gordon Beaton - 31 May 2006 21:20 GMT
> 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.

I googled for cygwin gcc jni and this was the second hit:

http://www.inonit.com/cygwin/jni/helloWorld/c.html

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

Suresh - 01 Jun 2006 00:42 GMT
Thank you Mr Gordon.

This link helped me solving my problem.

--Suresh


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.