proposal: cmd/cgo: cgo without a C toolchain
# Cgo Without C Toolchain ## Background Cgo provides a mechanism to incorporate C code into Go programs. Currently, it requires a C toolchain to be present on the host system whenever building code with `import "C"`. While this is natural when interacting with C, it creates significant friction for Go developers and users: - **End-user distribution**: It requires the end user to have a C toolchain installed in order to build or use the packages. - **Cross-compilation**: Cross-compiling pure Go programs is seamless, but cross-compiling cgo packages requires setting up C cross-compilers, as well as the build environment (sysroots, header files, etc.). In many common use cases, a Go package does not contain C function definitions; rather, it only interfaces with an existing pre-compiled shared library (`.so`) or static library (`.a`) using C declarations. For these packages, there is an opportunity to build them without using a C toolchain. Even in these cases, currently the build still requires a C toolchain. One main reason is that during the build, the `cgo` command will process the C preamble and generate glue code, some of which is in C and needs to be compiled with a C compiler. This proposal will tackle this issue. ## Proposal We propose a mechanism in the Go toolchain to build cgo packages that interface with pre-built C libraries without requiring a C toolchain to be installed. ### Goals - **No C toolchain at build time**: For a cgo program that only references
Posted by matloob on Sep 10, 2026, 3:44 PM
Tags
Related issues
Raise real-world problems, find people facing the same issue, and discuss solutions.2,000 issues0 comments
github (E-commerce)
proposal: cmd/cgo: cgo without a C toolchain
Replace PowerToys Run with Command Palette
VPS with a vRack leg
Possibility of Portal 1 Code Inclusion
Introducing NewPlayer
Metrics for PRs are never expiring ("memory leak")
ship even more of the compiler in source form
Flatpak Application TRACKING ISSUE
proposal: cmd/cgo: cgo without a C toolchain
# Cgo Without C Toolchain ## Background Cgo provides a mechanism to incorporate C code into Go programs. Currently, it requires a C toolchain to be present on the host system whenever building code with `import "C"`. While this is natural when interacting with C, it creates significant friction for Go developers and users: - **End-user distribution**: It requires the end user to have a C toolchain installed in order to build or use the packages. - **Cross-compilation**: Cross-compiling pure Go programs is seamless, but cross-compiling cgo packages requires setting up C cross-compilers, as well as the build environment (sysroots, header files, etc.). In many common use cases, a Go package does not contain C function definitions; rather, it only interfaces with an existing pre-compiled shared library (`.so`) or static library (`.a`) using C declarations. For these packages, there is an opportunity to build them without using a C toolchain. Even in these cases, currently the build still requires a C toolchain. One main reason is that during the build, the `cgo` command will process the C preamble and generate glue code, some of which is in C and needs to be compiled with a C compiler. This proposal will tackle this issue. ## Proposal We propose a mechanism in the Go toolchain to build cgo packages that interface with pre-built C libraries without requiring a C toolchain to be installed. ### Goals - **No C toolchain at build time**: For a cgo program that only references
Comments (0)
No comments yet. Start the discussion.