Go env: Troubleshoot Missing C Compiler
Problem
When build the project locally, the following errors occured
$ make build
# github.com/neuvector/neuvector/controller/common
../go/pkg/mod/github.com/neuvector/neuvector@v0.0.0-20250903232727-c2d83d9df18f/controller/common/output.go:55:13: undefined: LevelToPrio
../go/pkg/mod/github.com/neuvector/neuvector@v0.0.0-20250903232727-c2d83d9df18f/controller/common/output.go:92:14: undefined: LevelToPrio
# ... more undefined errorsThis build works fine in CI and other Linux environments, but fails locally.
Environment
- OS: Ubuntu 24.04.1 LTS (x86_64)
- Architecture: x86_64
- RKE2: v1.33.0+rke2r1
- go: go1.24.2Root Cause Analysis
- Ubuntu version: Same as CI → not the cause
- RKE2 version: Unrelated to local build
- Go version: Same as CI → not the cause
- Go environment: Potential cause
To inspect the Go environment, run:
go env -> check all of the var
go env CGO_ENABLED GOPROXY GOSUMDB GOOS GOARCHKey Difference Found
Upon comparing with the CI environment, this stood out:
| Machine | CGO_ENABLED | Build Result |
|---|---|---|
| CI | 1 | ✅ Success |
| Local | 0 | ❌ Undefined funcs |
Fixes
Problem 1: CGO_ENABLED=0
Some Go modules rely on CGO for system-level functionality. If CGO is disabled, files using import "C" are skipped during compilation, leading to undefined symbols.
Solution:
export CGO_ENABLED=1
make buildProblem 2: Missing C Compiler
After enabling CGO, you might hit this error:
# runtime/cgo
cgo: C compiler "cc" not found: exec: "cc": executable file not found in $PATHSolution: Install a C compiler
sudo apt update
sudo apt install build-essentialThis provides the required C toolchain (gcc, cc, make, etc.).
Summary
- Using
go envwas the key to identifying the environment difference. - The root cause of the build failure was a mismatch in the
CGO_ENABLEDsetting and a missing C compiler. By aligning the local environment with CI (enabling CGO and installing build tools), the issue was resolved.