Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to call a golang function using struct with fields of type string and map from C++ #40901

Closed
kanistha opened this issue Aug 19, 2020 · 1 comment

Comments

@kanistha
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.14.6 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/kaachar/Library/Caches/go-build"
GOENV="/Users/kaachar/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/kaachar/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.6/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.6/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/36/1n03rq0j7bn78d6kpv69fmmhcr6m0g/T/go-build210930523=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Our requirement is to call a function in Golang library in C++ code. Currently we are building the library using -buildmode=c-shared.
The function in golang library is using a struct as input and output. For example like:

type Request struct {
	X  string
	Y  string
	Z  map[string]string
}

If I try using C struture then it doesn't support string and map which makes it complex.
https://play.golang.org/p/Qjuu5j2nAv1

What did you expect to see?

We can call a golang function using struct with fields string and map from C++?
Is there any easier approach to solve this problem?

What did you see instead?

_cgo_export.c:124:22: error: incomplete result type 'struct SpeechRequest' in function definition
sample.go.txt

@ianlancetaylor
Copy link
Contributor

We don't use the issue tracker for questions. You will get better and faster answers using a forum. See https://golang.org/wiki/Questions. Thanks.

There is basically no way to create a Go string in C++, and there is definitely no way to create Go map value in C++, so there isn't going to be any reasonable way for you to call a Go function with that struct from C++.

@golang golang locked and limited conversation to collaborators Aug 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants