Note that there are some explanatory texts on larger screens.

plurals
  1. POMaking SWIG understand char** for using it in Java
    primarykey
    data
    text
    <p>I have following three files:</p> <p>sab1.hpp: </p> <pre><code>class CRectangle { int x, y; public: void set_values (int,int); void print(char **db); int area (); }; </code></pre> <p>sab1.cpp: </p> <pre><code>#include &lt;iostream&gt; #include "sab1.hpp" using namespace std; int CRectangle::area () { return (x*y); } void CRectangle::set_values (int a, int b) { x = a; y = b; } void CRectangle::print(char **db) { cout &lt;&lt;db[0]; } int main () { CRectangle rect; char *a[] = {"Hi", "bye" } ; rect.set_values (3,4); cout &lt;&lt; "area: " &lt;&lt; rect.area(); rect.print(&amp;a[0]); return 0; } </code></pre> <p>sab1.i : </p> <pre><code>%module Rec %{ /* Includes the header in the wrapper code */ #include "sab1.hpp" %} class CRectangle { int x, y; public: void set_values (int,int); void print(char **db); int area (); }; </code></pre> <p>I create various intermediary file using the following usual commands:</p> <p>1) swig -c++ -java sab1.i</p> <p>2) g++ -fpic -c sab1.cpp sab1_wrap.cxx -I /usr/lib/jvm/java-6-openjdk-i386/include/ -I /usr/lib/jvm/java-6-openjdk-i386/include/linux/</p> <p>Then I create a shared library using this: g++ --shared sab1.o sab1_wrap.o -o libegs.so</p> <p>Then I create a following Java file for accessing the functions of the C++ class: </p> <pre><code>public class Test { public static void main(String args[]) { System.loadLibrary("egs"); CRectangle a = new CRectangle(); a.set_values(4,5); System.out.println(a.area()); a.print("Hi"); } } </code></pre> <p>When I compile the Java File (javac -classpath . Test.java ), I get the following error:</p> <pre><code>Test.java:17: print(SWIGTYPE_p_p_char) in CRectangle cannot be applied to (java.lang.String) a.print("Hi"); ^ </code></pre> <p>So, how can I make the Java code understand the char ** variable? I have tried creating typemaps in the SWIG interface file (sab1.i) but I'm not able to correctly figure it out. </p> <p>Thanks in advance for the help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload