Last Updated: May 22, 2026
CGO is the Go feature that lets a Go program call functions written in C. It plugs the Go toolchain into the system's C compiler so a single go build produces one binary that contains both Go-compiled and C-compiled code. This chapter covers what CGO is, the special import "C" line, the preamble comment that holds C code and #cgo directives, how the build flow actually works, the CGO_ENABLED switch, and the cross-compilation caveat.