need help wrapping a C++ lib to Golang

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

need help wrapping a C++ lib to Golang

Miguel Michelsongs
Hello List,

Fist time here, I'm a C++ noob , so please don't be so rough with me :D

I've been trying to build a wrapper for IMGUI library, I've taken the CIMGUI implementation which is built for the purpose of build bindings to other languages.

I'm using the following interface:

%{
#include "../imgui/imgui.h"
#include "cimgui.h"
%}


with the following command to generate the wrapper


SWIG -c++ -go -gccgo -intgosize 64 cimgui.swig

and this for compile the wrapper the library with the compiled library:

gcc -c cimgui.cpp cimgui_wrap.cxx

my problem then is when I try to run go build the generated go file:

# command-line-arguments
./cimgui.go:39: missing function body for "SwigCgocall"
./cimgui.go:40: missing function body for "SwigCgocallDone"
./cimgui.go:41: missing function body for "SwigCgocallBack"
./cimgui.go:42: missing function body for "SwigCgocallBackDone" 
./cimgui.go:45: missing function body for "_swig_wrap_Swig_free" 

I really don't know how to proceed in this point , so I'm looking for some pointers from the experts on how can I manage this issue.

I've already opened an Github issue here https://github.com/swig/swig/issues/667 but it was closed because the gh issues are intended for swig development only (didn't note that before create the issue). 

thanks in advance ,
Best!

Miguel Michelson Martinez


------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: need help wrapping a C++ lib to Golang

William S Fulton
I'm not very familiar with the Go SWIG wrappers, but it might help if
you run an example as follows:

cd Examples/go/class
make check

I'm afraid that the output is rather verbose but amongst all the
verbiage, you should be able to work out what is essential to run. I'm
not sure if it correlates with the docs
http://swig.org/Doc3.0/Go.html#Go_running_swig.

William

On 29 April 2016 at 01:50, Miguel Michelsongs <[hidden email]> wrote:

> Hello List,
>
> Fist time here, I'm a C++ noob , so please don't be so rough with me :D
>
> I've been trying to build a wrapper for IMGUI library, I've taken the CIMGUI
> implementation which is built for the purpose of build bindings to other
> languages.
>
> I'm using the following interface:
>
> %{
> #include "../imgui/imgui.h"
> #include "cimgui.h"
> %}
>
>
>
> with the following command to generate the wrapper
>
>
> SWIG -c++ -go -gccgo -intgosize 64 cimgui.swig
>
> and this for compile the wrapper the library with the compiled library:
>
> gcc -c cimgui.cpp cimgui_wrap.cxx
>
> my problem then is when I try to run go build the generated go file:
>
> # command-line-arguments
> ./cimgui.go:39: missing function body for "SwigCgocall"
> ./cimgui.go:40: missing function body for "SwigCgocallDone"
> ./cimgui.go:41: missing function body for "SwigCgocallBack"
> ./cimgui.go:42: missing function body for "SwigCgocallBackDone"
>
> ./cimgui.go:45: missing function body for "_swig_wrap_Swig_free"
>
>
> I really don't know how to proceed in this point , so I'm looking for some
> pointers from the experts on how can I manage this issue.
>
> I've already opened an Github issue here
> https://github.com/swig/swig/issues/667 but it was closed because the gh
> issues are intended for swig development only (didn't note that before
> create the issue).
>
> thanks in advance ,
> Best!
>
> Miguel Michelson Martinez
>
>
> ------------------------------------------------------------------------------
> Find and fix application performance issues faster with Applications Manager
> Applications Manager provides deep performance insights into multiple tiers
> of
> your business applications. It resolves application problems quickly and
> reduces your MTTR. Get your free trial!
> https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
> _______________________________________________
> Swig-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/swig-user
>

------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: need help wrapping a C++ lib to Golang

Miguel Michelsongs
Hi William, Hi Lance
Thanks for your replies

SWIG Version 3.0.8 (Compiled with clang++ [x86_64-apple-darwin14.5.0])
Go Version 1.5.2 (but I've tried this with 1.4.2 too)

Now I've been able to avoid those errors because I've included the proper dependency

/* Includes the header in the wrapper code */
#include "./imgui/imgui.h"
#include "./cimgui/cimgui.h"
%}

/* Parse the header file to generate wrappers */
%include "./cimgui/cimgui.h"

But now I've get 

./cimgui_wrap.cxx:1749:10: error: C-style cast from '__va_list_tag *' to 'va_list' (aka '__builtin_va_list') is not allowed
./cimgui_wrap.cxx:1798:10: error: C-style cast from '__va_list_tag *' to 'va_list' (aka '__builtin_va_list') is not allowed
./cimgui_wrap.cxx:1830:10: error: C-style cast from '__va_list_tag *' to 'va_list' (aka '__builtin_va_list') is not allowed
./cimgui_wrap.cxx:1862:10: error: C-style cast from '__va_list_tag *' to 'va_list' (aka '__builtin_va_list') is not allowed
./cimgui_wrap.cxx:1911:10: error: C-style cast from '__va_list_tag *' to 'va_list' (aka '__builtin_va_list') is not allowed
./cimgui_wrap.cxx:1950:10: error: C-style cast from '__va_list_tag *' to 'va_list' (aka '__builtin_va_list') is not allowed
./cimgui_wrap.cxx:3437:10: error: C-style cast from '__va_list_tag *' to 'va_list' (aka '__builtin_va_list') is not allowed
./cimgui_wrap.cxx:3462:10: error: C-style cast from '__va_list_tag *' to 'va_list' (aka '__builtin_va_list') is not allowed
./cimgui_wrap.cxx:3786:10: error: C-style cast from '__va_list_tag *' to 'va_list' (aka '__builtin_va_list') is not allowed

I know that Swig have some issues casting va_list , but the code I'm trying to wrap is full of those arguments.
I've read the documentation but I don't know which is the best way to do it.

for example, for methods like this:

int ImFormatString(char* buf, int buf_size, const char* fmt, ...)
{
    va_list args;
    va_start(args, fmt);
    int w = vsnprintf(buf, buf_size, fmt, args);
    va_end(args);
    buf[buf_size-1] = 0;
    return (w == -1) ? buf_size : w;
}

which approach would I take ?

best

Atte.
Miguel Michelson Martinez
www.artenlinea.com

On Thu, May 12, 2016 at 5:19 PM, Ian Lance Taylor <[hidden email]> wrote:
On Thu, May 12, 2016 at 12:35 PM, William S Fulton
<[hidden email]> wrote:
> I'm not very familiar with the Go SWIG wrappers, but it might help if
> you run an example as follows:
>
> cd Examples/go/class
> make check
>
> I'm afraid that the output is rather verbose but amongst all the
> verbiage, you should be able to work out what is essential to run. I'm
> not sure if it correlates with the docs
> http://swig.org/Doc3.0/Go.html#Go_running_swig.


Which version of SWIG?  Which version of go?

It's generally easiest to use SWIG with go by using the go tool to run
SWIG.  You can do that by putting your SWIG interface in a file
foo.swigcxx and running `go build` as usual.  There are some brief
docs at https://golang.org/cmd/go/#hdr-Calling_between_Go_and_C.

Ian



> On 29 April 2016 at 01:50, Miguel Michelsongs <[hidden email]> wrote:
>> Hello List,
>>
>> Fist time here, I'm a C++ noob , so please don't be so rough with me :D
>>
>> I've been trying to build a wrapper for IMGUI library, I've taken the CIMGUI
>> implementation which is built for the purpose of build bindings to other
>> languages.
>>
>> I'm using the following interface:
>>
>> %{
>> #include "../imgui/imgui.h"
>> #include "cimgui.h"
>> %}
>>
>>
>>
>> with the following command to generate the wrapper
>>
>>
>> SWIG -c++ -go -gccgo -intgosize 64 cimgui.swig
>>
>> and this for compile the wrapper the library with the compiled library:
>>
>> gcc -c cimgui.cpp cimgui_wrap.cxx
>>
>> my problem then is when I try to run go build the generated go file:
>>
>> # command-line-arguments
>> ./cimgui.go:39: missing function body for "SwigCgocall"
>> ./cimgui.go:40: missing function body for "SwigCgocallDone"
>> ./cimgui.go:41: missing function body for "SwigCgocallBack"
>> ./cimgui.go:42: missing function body for "SwigCgocallBackDone"
>>
>> ./cimgui.go:45: missing function body for "_swig_wrap_Swig_free"
>>
>>
>> I really don't know how to proceed in this point , so I'm looking for some
>> pointers from the experts on how can I manage this issue.
>>
>> I've already opened an Github issue here
>> https://github.com/swig/swig/issues/667 but it was closed because the gh
>> issues are intended for swig development only (didn't note that before
>> create the issue).
>>
>> thanks in advance ,
>> Best!
>>
>> Miguel Michelson Martinez
>>
>>
>> ------------------------------------------------------------------------------
>> Find and fix application performance issues faster with Applications Manager
>> Applications Manager provides deep performance insights into multiple tiers
>> of
>> your business applications. It resolves application problems quickly and
>> reduces your MTTR. Get your free trial!
>> https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
>> _______________________________________________
>> Swig-user mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/swig-user
>>


------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: need help wrapping a C++ lib to Golang

William S Fulton
Varargs are non-trivial to wrap. Have you looked at the varargs
chapter for some ideas: http://swig.org/Doc3.0/Varargs.html.

William

On 12 May 2016 at 21:27, Miguel Michelsongs <[hidden email]> wrote:

> Hi William, Hi Lance
> Thanks for your replies
>
> SWIG Version 3.0.8 (Compiled with clang++ [x86_64-apple-darwin14.5.0])
> Go Version 1.5.2 (but I've tried this with 1.4.2 too)
>
> Now I've been able to avoid those errors because I've included the proper
> dependency
>
> /* Includes the header in the wrapper code */
> #include "./imgui/imgui.h"
> #include "./cimgui/cimgui.h"
> %}
>
> /* Parse the header file to generate wrappers */
> %include "./cimgui/cimgui.h"
>
>
> But now I've get
>
> ./cimgui_wrap.cxx:1749:10: error: C-style cast from '__va_list_tag *' to
> 'va_list' (aka '__builtin_va_list') is not allowed
> ./cimgui_wrap.cxx:1798:10: error: C-style cast from '__va_list_tag *' to
> 'va_list' (aka '__builtin_va_list') is not allowed
> ./cimgui_wrap.cxx:1830:10: error: C-style cast from '__va_list_tag *' to
> 'va_list' (aka '__builtin_va_list') is not allowed
> ./cimgui_wrap.cxx:1862:10: error: C-style cast from '__va_list_tag *' to
> 'va_list' (aka '__builtin_va_list') is not allowed
> ./cimgui_wrap.cxx:1911:10: error: C-style cast from '__va_list_tag *' to
> 'va_list' (aka '__builtin_va_list') is not allowed
> ./cimgui_wrap.cxx:1950:10: error: C-style cast from '__va_list_tag *' to
> 'va_list' (aka '__builtin_va_list') is not allowed
> ./cimgui_wrap.cxx:3437:10: error: C-style cast from '__va_list_tag *' to
> 'va_list' (aka '__builtin_va_list') is not allowed
> ./cimgui_wrap.cxx:3462:10: error: C-style cast from '__va_list_tag *' to
> 'va_list' (aka '__builtin_va_list') is not allowed
> ./cimgui_wrap.cxx:3786:10: error: C-style cast from '__va_list_tag *' to
> 'va_list' (aka '__builtin_va_list') is not allowed
>
>
> I know that Swig have some issues casting va_list , but the code I'm trying
> to wrap is full of those arguments.
> I've read the documentation but I don't know which is the best way to do it.
>
> for example, for methods like this:
>
> int ImFormatString(char* buf, int buf_size, const char* fmt, ...)
> {
>     va_list args;
>     va_start(args, fmt);
>     int w = vsnprintf(buf, buf_size, fmt, args);
>     va_end(args);
>     buf[buf_size-1] = 0;
>     return (w == -1) ? buf_size : w;
> }
>
>
> which approach would I take ?
>
> best
>
> Atte.
> Miguel Michelson Martinez
> www.artenlinea.com
>
> On Thu, May 12, 2016 at 5:19 PM, Ian Lance Taylor <[hidden email]> wrote:
>>
>> On Thu, May 12, 2016 at 12:35 PM, William S Fulton
>> <[hidden email]> wrote:
>> > I'm not very familiar with the Go SWIG wrappers, but it might help if
>> > you run an example as follows:
>> >
>> > cd Examples/go/class
>> > make check
>> >
>> > I'm afraid that the output is rather verbose but amongst all the
>> > verbiage, you should be able to work out what is essential to run. I'm
>> > not sure if it correlates with the docs
>> > http://swig.org/Doc3.0/Go.html#Go_running_swig.
>>
>>
>> Which version of SWIG?  Which version of go?
>>
>> It's generally easiest to use SWIG with go by using the go tool to run
>> SWIG.  You can do that by putting your SWIG interface in a file
>> foo.swigcxx and running `go build` as usual.  There are some brief
>> docs at https://golang.org/cmd/go/#hdr-Calling_between_Go_and_C.
>>
>> Ian
>>
>>
>>
>> > On 29 April 2016 at 01:50, Miguel Michelsongs
>> > <[hidden email]> wrote:
>> >> Hello List,
>> >>
>> >> Fist time here, I'm a C++ noob , so please don't be so rough with me :D
>> >>
>> >> I've been trying to build a wrapper for IMGUI library, I've taken the
>> >> CIMGUI
>> >> implementation which is built for the purpose of build bindings to
>> >> other
>> >> languages.
>> >>
>> >> I'm using the following interface:
>> >>
>> >> %{
>> >> #include "../imgui/imgui.h"
>> >> #include "cimgui.h"
>> >> %}
>> >>
>> >>
>> >>
>> >> with the following command to generate the wrapper
>> >>
>> >>
>> >> SWIG -c++ -go -gccgo -intgosize 64 cimgui.swig
>> >>
>> >> and this for compile the wrapper the library with the compiled library:
>> >>
>> >> gcc -c cimgui.cpp cimgui_wrap.cxx
>> >>
>> >> my problem then is when I try to run go build the generated go file:
>> >>
>> >> # command-line-arguments
>> >> ./cimgui.go:39: missing function body for "SwigCgocall"
>> >> ./cimgui.go:40: missing function body for "SwigCgocallDone"
>> >> ./cimgui.go:41: missing function body for "SwigCgocallBack"
>> >> ./cimgui.go:42: missing function body for "SwigCgocallBackDone"
>> >>
>> >> ./cimgui.go:45: missing function body for "_swig_wrap_Swig_free"
>> >>
>> >>
>> >> I really don't know how to proceed in this point , so I'm looking for
>> >> some
>> >> pointers from the experts on how can I manage this issue.
>> >>
>> >> I've already opened an Github issue here
>> >> https://github.com/swig/swig/issues/667 but it was closed because the
>> >> gh
>> >> issues are intended for swig development only (didn't note that before
>> >> create the issue).
>> >>
>> >> thanks in advance ,
>> >> Best!
>> >>
>> >> Miguel Michelson Martinez
>> >>
>> >>
>> >>
>> >> ------------------------------------------------------------------------------
>> >> Find and fix application performance issues faster with Applications
>> >> Manager
>> >> Applications Manager provides deep performance insights into multiple
>> >> tiers
>> >> of
>> >> your business applications. It resolves application problems quickly
>> >> and
>> >> reduces your MTTR. Get your free trial!
>> >> https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
>> >> _______________________________________________
>> >> Swig-user mailing list
>> >> [hidden email]
>> >> https://lists.sourceforge.net/lists/listinfo/swig-user
>> >>
>
>

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Loading...