A Go program might need to use a hardware driver implemented in C, query an embedded database implemented in C++, or use some linear algebra routines implemented in Fortran. C has long been the lingua franca of programming, so many packages intended for widespread use export a C-compatible API, regardless of the language of their implementation.
In this section, we’ll build a simple data compression program that
cgo, a tool that creates Go bindings for C functions.
Such tools are called foreign-function interfaces (FFIs), and
cgo is not the only one for Go programs.
swig.org) is another; it provides more complex
features for integrating with C++ classes, but we won’t show it here.