Re: Problem with using C++ code in Go lang

Tomasz Rojek <[email protected]>
Newsgroups gmane.comp.programming.swig
Message-ID <CAGGQbxHUrdNJEO6wc78C_F=yKjZ7z2aY4MyauGgb=FHSfkjpNg@mail.gmail.com>
> Hi
>
> I want to use functions from HeliosDacAPI.cpp file (
> https://github.com/Grix/helios_dac/tree/master/sdk) in my Go program.
>
> I make a go module (HeliosDacAPI) which contains files:
>
> HeliosDacAPI.cpp (from repo)
> HeliosDACAPI.h (from repos)
> HeliosDAC.h (from repo)
> HeliosDAC.cpp (from repo)
> HeliosDacAPI.swig which contains:
> ```
> %module HeliosDacAPI
>
> %include "HeliosDacAPI.h"
> %include "HeliosDac.h"%
> ```
>
> Then I generate wrappers to c++ code by using command: `swig -go -c++ -cgo
> -intgosize 64 -module HeliosDacAPI HeliosDacAPI.cpp`
>
> Then I create a go project, include HeliosDacAPI module and try to use
> OpenDevices() function.
>
> ```
> package main
>
> import (
>   "HeliosDacAPI"
> )
>
> func main() {
>   helios := HeliosDacAPI().OpenDevices()
>   fmt.Printf("%+v", helios)
> }
> ```
>
> After execution (`go run main.go`) of above code I got realy long list of
> errors and warnings. I include only part of it:
>
> `# HeliosDacAPI
> HeliosDac.h:80: Warning 301: class keyword used, but not in C++ mode.
> # HeliosDacAPI
> HeliosDacAPI_wrap.c:245:53: error: unknown type name ‘bool’
>   245 | void _wrap_inited_set_HeliosDacAPI_c79d16aa38ff71d1(bool
> _swig_go_0) {
>       |                                                     ^~~~
> HeliosDacAPI_wrap.c:255:1: error: unknown type name ‘bool’
>   255 | bool _wrap_inited_get_HeliosDacAPI_c79d16aa38ff71d1() {
>       | ^~~~
> HeliosDacAPI_wrap.c: In function
> ‘_wrap_inited_get_HeliosDacAPI_c79d16aa38ff71d1’:
> HeliosDacAPI_wrap.c:256:3: error: unknown type name ‘bool’
>   256 |   bool result;
>       |   ^~~~
> HeliosDacAPI_wrap.c:257:3: error: unknown type name ‘bool’
>   257 |   bool _swig_go_result;
>       |   ^~~~
> HeliosDacAPI_wrap.c:260:13: error: ‘bool’ undeclared (first use in this
> function)
>   260 |   result = (bool)inited;
>       |             ^~~~
> HeliosDacAPI_wrap.c:260:13: note: each undeclared identifier is reported
> only once for each function it appears in
> HeliosDacAPI_wrap.c:260:18: error: expected ‘;’ before ‘inited’
>   260 |   result = (bool)inited;
>       |                  ^~~~~~
>       |                  ;
> .....
> `
>
> I assume that I made some mistake with preparing the wrappers. Could you
> help me and give me some hints how should I use swig in order to use
> HeliosDacAPI functions in Go?
>
> Best regards,
> Tomasz Rojek
>
>

_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.