cgo

The Go feature that lets Go code call C code, which links the program to C libraries on the build and target machines.

In more detail

Some standard library packages, such as parts of the network name lookup code, can use cgo when it is enabled. Setting CGO_ENABLED=0 turns it off so the build produces a static binary that runs in scratch or distroless images. If a dependency truly needs C, you need the C library in the runtime image too.

Example

CGO_ENABLED=0 go build -o app .

Related terms

Taught in

References