Re: New user need help calling C++ code from Java

Alessio M <[email protected]> Sat, 28 Sep 2024 11:11:39 +0100
Newsgroups gmane.comp.programming.swig
Message-ID <CAL_VXbbj8wK1roXWDt_Srkt=Rw_=xzLfrQemuBK0igCnCS9JaA@mail.gmail.com>
--===============8965783828135704044==
Content-Type: multipart/alternative; boundary="000000000000cad03606232b34c2"

--000000000000cad03606232b34c2
Content-Type: text/plain; charset="UTF-8"

SWIG will create the java classes for you and it's actually well documented
for basics and intermediate - some advanced stuff needs reading the .i
code. But the docs will give you pretty solid grounds

https://www.swig.org/Doc4.2/Java.html#Java
https://anyline.com/news/java-c-swig-type-maps

Il giorno ven 27 set 2024 alle ore 23:10 Siddharth Jain <[email protected]>
ha scritto:

> 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.
> _______________________________________________
> Swig-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/swig-user
>

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

<div dir=3D"ltr"><div>SWIG will create the java=C2=A0classes for you and it=
&#39;s=C2=A0actually well documented for basics and intermediate - some adv=
anced stuff needs reading the .i code. But the docs will give you pretty so=
lid grounds</div><div><br></div><div><a href=3D"https://www.swig.org/Doc4.2=
/Java.html#Java" target=3D"_blank">https://www.swig.org/Doc4.2/Java.html#Ja=
va</a><br></div><a href=3D"https://anyline.com/news/java-c-swig-type-maps" =
target=3D"_blank">https://anyline.com/news/java-c-swig-type-maps</a><br></d=
iv><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">Il =
giorno ven 27 set 2024 alle ore 23:10 Siddharth Jain &lt;<a href=3D"mailto:=
[email protected]">[email protected]</a>&gt; ha scritto:<br></div><blockq=
uote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1p=
x solid rgb(204,204,204);padding-left:1ex"><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 it. I managed to get SWIG install=
ed.</div><div><br></div><div>My problem is this: Say I have a C++ function:=
</div><div><br></div><div>void foo(SomeStruct&amp; s)</div><div><br></div><=
div>I have a very deep hierarchy where SomeStruct contains StructA, then St=
ructA contains StructB and so on. It will be a nightmare for me to create J=
ava classes corresponding to all these structs. This is something I was hop=
ing SWIG would handle for me transparently but it does not seem to.</div><d=
iv><br></div><div>My interface file is simply this:</div><div><br></div><di=
v><div style=3D"color:rgb(204,204,204);background-color:rgb(31,31,31);font-=
family:Consolas,&quot;Courier New&quot;,monospace;font-size:16px;line-heigh=
t:22px;white-space:pre-wrap"><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"color:rgb(212,212,212)">%</spa=
n>{</div><div><span style=3D"color:rgb(197,134,192)">#include</span><span s=
tyle=3D"color:rgb(86,156,214)"> </span><span style=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"color:rgb(212,212,212)">%</spa=
n>include <span style=3D"color:rgb(206,145,120)">&quot;mylib.hpp&quot;</spa=
n></div></div></div><div><br></div><div>When I try to process it like this:=
</div><div><br></div><div>$ swig -c++ -java -package 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 directory<br></div><div><br></=
div><div>Can anyone help me with this?</div><div><br></div><div>S.</div></d=
iv>
_______________________________________________<br>
Swig-user mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">Swig-u=
[email protected]</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/swig-user" rel=3D"n=
oreferrer" target=3D"_blank">https://lists.sourceforge.net/lists/listinfo/s=
wig-user</a><br>
</blockquote></div>

--000000000000cad03606232b34c2--


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


--===============8965783828135704044==
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

--===============8965783828135704044==--