Search code examples
gocgo

Calling Go library from C Code


I've found a ton of information about how to use cgo to call C libraries from Go, but I'm interested in the opposite: writing a library in Go, and linking/using it in various C programs.

Is this possible? Any good resources for this? Thanks.


Solution

  • This can not be done currently. Go has to be the entry point and without the use of gccgo, you can't compile Go into a shared library.

    There is a proposal to change this, so it may or may not be an option at some point. Refer to this document for details.