How do I call C from Go using the "foreign function interface"

c go ffi
pauldoo picture pauldoo · Apr 29, 2010 · Viewed 12.2k times · Source

How do I use Go's "foreign function interface" to call out to a C function?

This interface is mentioned on the FAQ, but I cannot see it mentioned elsewhere in the docs.

Answer

Paul Wicks picture Paul Wicks · Apr 29, 2010

Check out this file from the Go repository. It shows how to wrap a C library in Go and has quite a few comments that explain the process.