This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

cni-3.txt


updated http://gcc.gnu.org/java/cni-2.txt for 3.3.4

cni-3.txt
Here is a sample project demonstrating the basics of building a CNI
application with GCJ version 3.3.4.

It assumes that you have installed the binaries in a directory
in your path.

==> Makefile <==
sample:  sample.o sampNat.o
       gcj -o sample \
               sample.o sampNat.o -lstdc++ --main=sample

sample.o:  sample.class
       gcj -c sample.class

sample.class: sample.java
       gcj -C sample.java

sample.h: sample.class
       gcjh sample

sampNat.o: sample.h sampNat.cc
       g++ -c sampNat.cc

clean:
       rm -f sample sample.o sampNat.o sample.class sample.h

==> sample.java <==
public class sample {
 public native void myNative(String s);

 public void myJava(String s)
 {
   s = s + ", Java";
   System.out.println(s);
 }

 public static void main(String args[]) {
   sample x = new sample();
   x.myJava("Hello");
   x.myNative("Hello, Java (from C++)");
   x.myJava("Goodbye");
 }
}

==> sampNat.cc <==
#include <gcj/cni.h>
#include "sample.h"
#include <java/io/PrintStream.h>
#include <java/lang/System.h>
#include <java/lang/String.h>

#include <iostream>
using namespace std;

void sample::myNative(java::lang::String *s)
{
 cout << "Hello, C++" << endl;

 java::lang::System::out->println(s);
}



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