Mail Archives: cygwin/2003/05/21/17:55:13
Shaddy -
I have uploaded some sample code to http://www.whitecaps.net/jni/expr.jar . The expr/jni/hello directory contains a "standard" JNI example (where java calls into a C++ program) that works on Cygwin and has an ant buildfile (I assume you are using ant.....if not, get it and you'll be happy). The expr/jni/invoke directory has an example using the JNI invocation interface, where a C++ program creates a JVM to print "hello". Output is pasted below.
Also, if you haven't seen it, look at the excellent writeup on JNI for Cygwin at http://www.inonit.com/cygwin/
Alan Thompson
****************************************************************************************************
cd expr/jni/hello
ant
Buildfile: build.xml
clean:
init:
[mkdir] Created dir: C:\export\expr\jni\hello\bin
[mkdir] Created dir: C:\export\expr\jni\hello\gen
javaSrcComp:
[javac] Compiling 2 source files to C:\export\expr\jni\hello\bin
ctags:
javaComp:
javah:
[echo] building *_jni.h...
ccComp:
[mkdir] Created dir: C:\export\expr\jni\hello\ctmp
[copy] Copying 2 files to C:\export\expr\jni\hello\ctmp
[echo] Compiler Name: g++
[echo] Compiler Version:
[exec] g++ (GCC) 3.2 20020927 (prerelease)
[exec] Copyright (C) 2002 Free Software Foundation, Inc.
[exec] This is free software; see the source for copying conditions. There is NO
[exec] warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[echo] Compiling for Cygwin...
[echo] Linking for Cygwin...
[delete] Deleting directory C:\export\expr\jni\hello\ctmp
build:
go:
[java] loading library
[java] calling sayHello
[java] Hello World from C!
[java] trying to get array
[java] answerArrayObj=0x8b74cc
[java] trying to get elem[0]
[java] elem0=0x8b74d0
[java] elemClass=0x8b74d4
[java] valueFieldID=0x22
[java] trying to get valueObj
[java] valueObj=0x8b74d8
[java] trying to get string chars
[java] initial string = 'initial value from java'
[java] trying to set string chars
[java] newJString=0x8b74dc
[java] getting constructor MID
[java] msgCID=0x8bbf18
[java] calling constructor
[java] trying to set string chars
[java] newJString2=0x8b74e4
[java] setting newElem value
[java] trying to set elem[1]
[java] sayHello() returning
[java] sayHello done
[java] answer[ 0 ] = 'Hello World from C!'
[java] answer[ 1 ] = 'the new C string value'
[java] answer[ 2 ] = 'initial value from java'
clean:
[delete] Deleting directory C:\export\expr\jni\hello\bin
[delete] Deleting directory C:\export\expr\jni\hello\gen
BUILD SUCCESSFUL
Total time: 9 seconds
cd expr/jni/invoke
ant
Buildfile: build.xml
clean:
init:
[mkdir] Created dir: C:\export\expr\jni\invoke\bin
javaComp:
[javac] Compiling 1 source file to C:\export\expr\jni\invoke\bin
ccCygwin:
[echo] Compiling C++ for Cygwin
dlltoolCygwin:
ccCompCygwin:
[echo] Compiler Name: g++
[echo] Compiler Version:
[exec] g++ (GCC) 3.2 20020927 (prerelease)
[exec] Copyright (C) 2002 Free Software Foundation, Inc.
[exec] This is free software; see the source for copying conditions. There is NO
[exec] warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
ccSun:
ccComp:
build:
go:
goCygwin:
[exec] <C++> program starting
[exec] <java> Hello World from C!
[exec] <C++> program terminating
goSun:
clean:
[delete] Deleting directory C:\export\expr\jni\invoke\bin
BUILD SUCCESSFUL
Total time: 12 seconds
At 02:12 PM 5/20/2003 +0800, Shaddy Baddah wrote:
>I am having exactly the same problem trying to build Java JNI's under Cygwin
>(actually, they are the examples from the 'GNU Win32 related projects'
>page ). Robert Bercik, did discover a fix for the problem you encountered?
>
>I have more weirdness to describe. I can run the Java app that loads in the
>JNI under a regular Windows 2000 'cmd' window and it works fine, regardless
>of whether there is a cygwin1.dll active or not. But if I try and run the
>same Java app from within a cygwin shell, it crashes in the same way. There
>must be a simple explanation/fix to this one. Help would be greatly
>appreciated.
>
>Thanks in advance,
>Shaddy
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -