1

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.

scosman
  • 2,343
  • 18
  • 34
  • Current point of investigation: looking at the "mobile" library's iOS support. Looks like it's possible somehow but very early. – scosman Feb 17 '15 at 17:49

1 Answers1

1

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.

jimt
  • 25,324
  • 8
  • 70
  • 60
  • For those of you looking for non-library answer, see this one, also by jimt http://stackoverflow.com/questions/6125683/call-go-functions-from-c/6147097#6147097 – scosman Feb 17 '15 at 18:06
  • 2
    Per @jimt's second paragraph - it's now possible. Go's tip branch now supports `go build -buildmode=c-archive yourpkg` which will build a library that does not need to be the entry point. The document he pointed to has more details, but I've tested this and it's working. – scosman May 26 '15 at 18:56