...

/

Interaction with C and C++

Interaction with C and C++

Go lets its users write programs in combination with Go and C/C++. This lesson covers how a Go program can have functionalities of C and C++ imported in it.

We'll cover the following...

Interacting with C

The cgo program provides the mechanism for FFI-support (Foreign Function Interface) to allow safe calling of C libraries from Go code. Here is the link to the primary cgo documentation. The cgo replaces the normal Go-compilers, and it outputs Go and C files that can be combined into a single Go package. It is good practice to combine the calls to C in a separate package. The following import is then necessary in your Go program:

import "C"

and usually also:

 ...