5 ms·
Go interoperates pretty well with C - so you would have to create a thin C layer on top of your C++ code. This is one problem I constantly have with C++, it is
by _ph_ 6y ago
Go interoperates pretty well with C - so you would have to create a thin C layer on top of your C++ code. This is one problem I constantly have with C++, it is pretty much its own world.
I have wrapped a large C++ library for Go it was a pretty straight forward process. I created a file with C callable functions that get passed pointers to the C++ objects and invoke the corresponding methods on that object. On the Go side pointer gets wrapped in a struct type for each C++ class and in the methods on that type I call the C functions. Works great.
- pansa2 6y ago> I have wrapped a large C++ library for Go How well does it work the other way round - calling Go from C/C++? IIRC when I first looked into doing that, it wasn’t really possible - only threads that were started by Go could run Go code. In particular, `main` had to be in Go and couldn’t be in C++. Does that restriction still apply?
- _ph_ 6y agoI have created shared libraries with Go which can be called from C, no problems. Those shared libraries can start their own goroutines quite fine and can call back into the C application. Usually it is a good idea to call back into the C application from the thread the Go function called from C was running.