How to use c++ with go

Hi, there is an open-source library: https://github.com/infinispan/cpp-client that I need to write a wrapper for it using golang.
The library has “c header files” and the library is written in c++.

I don’t want to use “SWIG”

I use windows 10 OS , with gcc and g++ installed.

You cannot call C++ code directly from Go. If you don’t want to use SWIG, then you need to write your own C functions that wrap the C++ functions you need to call and then call the C functions from Go. This example doesn’t work on the Go playground because it doesn’t seem to support cgo (or I just don’t know how to enable it), but if you save it to your computer and separate out the files, it works: https://play.golang.org/p/bBoAxJd1eZf

1 Like