invoke GCJ .o files from C/C++ program

Cecilia Vy-Ai Le a1tv86@yahoo.com
Thu Jul 6 15:55:00 GMT 2000


Hi,

Jeff Sturm wrote:
>What version of gcj/libgcj did you use?  If you
downloaded 2.95.1, 
>JNI will not be available.  (You can get a working 
>JNI from recent snapshots of the compiler and
library.)

-- I am working with the snapshot on June 20,2000.
Libgcj was built with option --enable-threads=none.
I am trying to call JNI_CreateJavaVM(), but it fails.
Then, I logged pr 279.

>JNI will not resolve classes at compile time, so you
> must find anotherway to get your classes linked from
> the static archive, or use a shared library instead.

-- I stop calling JNI.

>You may find it simpler and easier to use the CNI
>interface.  It allows you to create and invoke Java
> objects directly from C++ code.  With CNI
>you must use a Java main() method for program
startup,
> not a C/C++ main() function.  But this startup class
> may simply invoke the rest of your C++ app.

-- Then, I create the following files.  I create
executeable MainApp.  When I run it, it stops when
trying to invoke method printLine().  I walk through
the debugger, and see that java::lang:Object does not
recognize method printLine() (the method is hidden
some how in the class Object).  Does CNI have any API
to invoke this method for now?

===MainApp.java===
public class MainApp
{
  private int version;
  public native static void run();
  public static void main(String args[])
  {
    run();
  }
}
===RunApp.cc===
#include <gcj/cni.h>
#include "MainApp.h"
#include "JavaHello.h"

void JavaMain::run (void)
{
  JavaTool *psTool = new JavaTool();
  psTool->printLine();
}
===JavaHello.java===
public class JavaTool {
  public void printLine(){
    System.out.println("Hello World from Java");
  }
}
===End===

Thanks for your helps,
Cecilia




__________________________________________________
Do You Yahoo!?
Send instant messages & get email alerts with Yahoo! Messenger.
http://im.yahoo.com/


More information about the Java mailing list