Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call Java from C++ using SWIG?

Tags:

java

c++

swig

I am able to call C++ code from Java using SWIG but I can't find any documentation on how to do the reverse (call Java from C++).

The official SWIG documentation says (http://www.swig.org/Doc1.3/Java.html#java_overview): "SWIG enables a Java program to easily call into C/C++ code from Java. Historically, SWIG was not able to generate any code to call into Java code from C++. However, SWIG now supports full cross language polymorphism and code is generated to call up from C++ to Java when wrapping C++ virtual methods."

But I can't find where it says how to do it! Any help is greatly appreciated. Thank you.

like image 200
Ben Avatar asked Jul 06 '10 21:07

Ben


1 Answers

Actually this is possible and I have implemented it based on inheriting a virtual class from C++ to Java.

You can find solution in chapter "24.5 Cross language polymorphism using directors" of Java part of SWIG document.

like image 170
Qinjin Avatar answered Sep 21 '22 17:09

Qinjin