CNI invocation [was Re: Segfault on simple HelloWorld]

James CE Johnson jcej@tragus.org
Sat Apr 1 00:00:00 GMT 2000


Bryce McKinlay wrote:
> James CE Johnson wrote:
>> > Forgive the newcomer...
> >
> > I'm interested in using Java classes from my C++ app. I just tripped
> > across gcj a few weeks ago & started messing with it. The simple test
> > case I have below segfaults.
>> Hi James,
>> CNI so far has no "invocation interface" to allow Java code to be called
> from a program with a C/C++ "main" method. The libgcj runtime assumes that
> some initialization code has been run at startup (such as setting up the
> java.lang.Thread environment, but there are possibly a few other things).
> This initialization code only gets run from a java binary generated by gcj,
> before the java programs "main" gets run.

Ah. Well. I guess that makes sense.
Not to be deterred I tried your suggestion: A simple Java wrapper for a
traditional "main". Strange I suppose, but it seems to behave.
[jcej@node04 tmp]$ cat Main.java
public class Main
{
 public native static void run();
 public static void main(String args[])
 {
 run();
 }
}
[jcej@node04 tmp]$ cat Run.cpp
#include "Main.h"
#include "Test.h"
#include <cni.h>
void Main::run(void)
{
 Test * test = new Test();
 test->HelloWorld();
 // deleting Java objects is
 // apparently a bad idea...
 // delete test;
 return;
}


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /