This is the mail archive of the
java-discuss@sourceware.cygnus.com
mailing list for the Java project.
Re: Call compiled Java from C/C++?
- To: Vito BAGGIOLINI <Vito dot nospam dot Baggiolini at cern dot ch>
- Subject: Re: Call compiled Java from C/C++?
- From: Tom Tromey <tromey at cygnus dot com>
- Date: Fri, 1 Oct 1999 08:52:04 -0700
- Cc: java-discuss at sourceware dot cygnus dot com
- References: <37F45C7B.1720E1CF@cern.ch>
>>>>> "Vito" == Vito BAGGIOLINI <Vito.nospam.Baggiolini@cern.ch> writes:
Vito> I understand that CNI is primarily intended to call C/C++
Vito> routines from a Java 'main' program.
Vito> But is the opposite possible, i.e. to call a compiled Java code
Vito> from a C/C++ 'main' program? (With JNI this is possible, but
Vito> quite clumsy).
It is possible, but it might be hard.
In a gcj-compiled program, main() is actually written in C (the
"--main" option generates and compiles a simple C program).
However, the runtime more or less assumes that the program is
following the startup sequence given in prims.cc (see JvRunMain).
You could write your own main() that follows these lines.
This is a bad idea, though, because the implementation of JvRunMain is
a detail which we will change at our convenience.
I haven't looked to see how JNI works when you want to start the JVM
once your program is already running. Since we do want to implement
JNI eventually, we will need to support this. So if you hack on it,
try to more-or-less follow JNI (while keeping in the spirit of CNI, if
this idea makes sense), and tell us what you come up with.
FYI, CNI actually goes both ways: it is a way for Java to call C++
native methods, but it also lets C++ code call Java methods directly.
Tom