wood burning stoves 2.0*
The moose likes Other JSE/JEE APIs and the fly likes JNI Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "JNI Problem" Watch "JNI Problem" New topic
Author

JNI Problem

shawn kennedy
Ranch Hand

Joined: Oct 31, 2002
Posts: 67
I have a horrible problem with compiling c programs using jni.The moment i try to use the following command:
gcc -Wall -Ic:\j2sdk1.4.2_03\include -Ic:\j2sdk1.4.2_03\include\win32 -o CapscanSortCode CapscanSortCode.c
it throws a while load of errors pertaining to jni.h file like


c:/j2sdk1.4.2_03/include/jni.h:1863: error: parse error before '*' token
c:/j2sdk1.4.2_03/include/jni.h:1864: error: parse error before '*' token
c:/j2sdk1.4.2_03/include/jni.h:1872: error: parse error before '}' token
c:/j2sdk1.4.2_03/include/jni.h:1872: warning: type defaults to `int' in declarat
ion of `JDK1_1InitArgs'
c:/j2sdk1.4.2_03/include/jni.h:1872: warning: data definition has no type or sto
rage class
c:/j2sdk1.4.2_03/include/jni.h:1888: error: parse error before '*' token
c:/j2sdk1.4.2_03/include/jni.h:1888: warning: no semicolon at end of struct or u
nion
c:/j2sdk1.4.2_03/include/jni.h:1890: error: parse error before '*' token
c:/j2sdk1.4.2_03/include/jni.h:1892: error: parse error before '*' token
c:/j2sdk1.4.2_03/include/jni.h:1894: error: parse error before '*' token
c:/j2sdk1.4.2_03/include/jni.h:1896: error: parse error before '*' token
c:/j2sdk1.4.2_03/include/jni.h:1927: warning: return type defaults to `int'
c:/j2sdk1.4.2_03/include/jni.h: In function `__declspec':
c:/j2sdk1.4.2_03/include/jni.h:1928: error: parse error before "JNI_GetDefaultJa
vaVMInitArgs"
c:/j2sdk1.4.2_03/include/jni.h:1928: error: declaration for parameter `__stdcall
' but no such parameter



I cant figure out how to move forward and i desperately need to know how to do this.Any help would be really great.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Here is the definition of CFLAGS that I use to build native methods with Cygwin gcc under Windows:

CFLAGS=-mrtd -D_REENTRANT -D_GNU_SOURCE -D__int64="long long" \
-mno-cygwin $(INCLUDES) -I$(JAVAHOME)/include -I$(JAVAHOME)/include/$(PLATFORM)

LDFLAGS looks like

LDFLAGS=-mno-cygwin -Wl,--add-stdcall-alias -shared -luser32 -lgdi32 \
-lglu32 -lopengl32 -L$(JAVAHOME)/lib -ljawt

I believe that it's the -D__int64="long long" that should fix your problem.


[Jess in Action][AskingGoodQuestions]
shawn kennedy
Ranch Hand

Joined: Oct 31, 2002
Posts: 67
Hi,
Im a bit confused about this
Here is the definition of CFLAGS that I use to build native methods with Cygwin gcc under Windows:

CFLAGS=-mrtd -D_REENTRANT -D_GNU_SOURCE -D__int64="long long" \
-mno-cygwin $(INCLUDES) -I$(JAVAHOME)/include -I$(JAVAHOME)/include/$(PLATFORM)

LDFLAGS looks like

LDFLAGS=-mno-cygwin -Wl,--add-stdcall-alias -shared -luser32 -lgdi32 \
-lglu32 -lopengl32 -L$(JAVAHOME)/lib -ljawt

I believe that it's the -D__int64="long long" that should fix your problem.


What i dont understand is where am i suppose to specify the cflags and ldflags options
in cygwin i normally just give the following command:

gcc -mno-cygwin -I$jdk/include -I$jdk/include/win32 -Wl,--add-stdcall-alias -shared -o HelloWorld.dll HelloWorld.c
Now where do i specify the cflags on the command line and how

and about -D__int64="long long" where do i specify that .
Im sorry for being a paing but im new to JNI and totally confused.
Regards,
Madhu
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Most people using gcc control it using make. These definitions could
go in your Makefile, and make uses them automatically (they depend on
some other definitions you'd supply, like PLATFORM and JAVAHOME.)

But if you're not using make, then you can just add the important bits
to your command line, to make it look something like

gcc -D__int64="long long" -mrtd -D_REENTRANT -mno-cygwin -I$jdk/include -I$jdk/include/win32 -Wl,--add-stdcall-alias -shared -o
HelloWorld.dll HelloWorld.c
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JNI Problem