New user need help calling C++ code from Java

Siddharth Jain <[email protected]> Fri, 27 Sep 2024 15:09:46 -0700
Newsgroups gmane.comp.programming.swig
Message-ID <CAPqV3pQhBvH4zOwtKfL_CksD_W9QV2ydU5CWn-0ZhFh=7DR4BA@mail.gmail.com>
--===============3288683956107291036==
Content-Type: multipart/alternative; boundary="0000000000009efc600623211d87"

--0000000000009efc600623211d87
Content-Type: text/plain; charset="UTF-8"

Hello,

I have a C++ library that I'd like to call from Java. I came across SWIG as
a tool that can help with it. I managed to get SWIG installed.

My problem is this: Say I have a C++ function:

void foo(SomeStruct& s)

I have a very deep hierarchy where SomeStruct contains StructA, then
StructA contains StructB and so on. It will be a nightmare for me to create
Java classes corresponding to all these structs. This is something I was
hoping SWIG would handle for me transparently but it does not seem to.

My interface file is simply this:

/* File: example.i */
%module test
%{
#include "mylib.hpp"
%}

%include "mylib.hpp"

When I try to process it like this:

$ swig -c++ -java -package mypackage -outdir java_out example.i

I get:

Unable to open file java_out/StructA.java: No such file or directory

Can anyone help me with this?

S.

--0000000000009efc600623211d87
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hello,<div><br></div><div>I have a C++ library that I&#39;=
d like to call from Java. I came across SWIG as a tool that can help with i=
t. I managed to get SWIG installed.</div><div><br></div><div>My problem is =
this: Say I have a C++ function:</div><div><br></div><div>void foo(SomeStru=
ct&amp; s)</div><div><br></div><div>I have a very deep hierarchy where Some=
Struct contains StructA, then StructA contains StructB and so on. It will b=
e a nightmare for me to create Java classes corresponding to all these stru=
cts. This is something I was hoping SWIG would handle for me transparently =
but it does not seem to.</div><div><br></div><div>My interface file is simp=
ly this:</div><div><br></div><div><div style=3D"color:rgb(204,204,204);back=
ground-color:rgb(31,31,31);font-family:Consolas,&quot;Courier New&quot;,mon=
ospace;font-size:16px;line-height:22px;white-space:pre"><div><span style=3D=
"color:rgb(106,153,85)">/* File: example.i */</span></div><div><span style=
=3D"color:rgb(212,212,212)">%</span>module test</div><div><span style=3D"co=
lor:rgb(212,212,212)">%</span>{</div><div><span style=3D"color:rgb(197,134,=
192)">#include</span><span style=3D"color:rgb(86,156,214)"> </span><span st=
yle=3D"color:rgb(206,145,120)">&quot;mylib.hpp&quot;</span></div><div><span=
 style=3D"color:rgb(212,212,212)">%</span>}</div><br><div><span style=3D"co=
lor:rgb(212,212,212)">%</span>include <span style=3D"color:rgb(206,145,120)=
">&quot;mylib.hpp&quot;</span></div></div></div><div><br></div><div>When I =
try to process it like this:</div><div><br></div><div>$ swig -c++ -java -pa=
ckage mypackage -outdir java_out example.i</div><div><br></div><div>I get:<=
/div><div><br>Unable to open file java_out/StructA.java: No such file or di=
rectory<br></div><div><br></div><div>Can anyone help me with this?</div><di=
v><br></div><div>S.</div></div>

--0000000000009efc600623211d87--


--===============3288683956107291036==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============3288683956107291036==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user

--===============3288683956107291036==--