Using GCC-java as a scripting language on top of C++ - possible?

Bryce McKinlay bryce@mckinlay.net.nz
Mon Oct 20 22:36:00 GMT 2003


On Oct 19, 2003, at 11:40 AM, Asfand Yar Qazi wrote:

> I want to use gcj as a scripting language on top of a c++-written 
> engine: is this possible?

I don't know what you mean by "scripting language", but if you mean 
putting a Java wrapper around some existing C++ classes, then yes, 
sure!

> Assuming the ABIs are compatible, I'm assuming I just need to find a 
> way to generate java source files from C++ header files, and I'll be 
> able to use the C++ classes as normal java classes (for simple things, 
> anyway - no deriving, probably.)
> I'm prepared to write java interfaces for the C++ classes manually, if 
> necessary.

You can't generate a Java interface automatically from C++ headers. The 
ABIs for C++ and Java are compatible such that code in each of the two 
languages can interoperate, but you can't call a non-Java C++ class 
directly from Java. For one thing, not all C++ types are available in 
Java.

The way to do this is to define an interface into your native code in 
terms of "native" methods in a Java class, then implement those methods 
in C++ such that they wrap your C++ classes.

Basically, with CNI, Java classes can be used as if they were C++ 
classes - but not vice-versa!

Regards,

Bryce.



More information about the Java mailing list