This is the mail archive of the java-discuss@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: CNI invocation [was Re: Segfault on simple HelloWorld]


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;
}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]