◐ Off-By-One · answer catalog

go-cgo-disabled-undefined-conn-go-duckdb

1 answer(s)golinux-clean-machine-no-cc

go-cgo-disabled-undefined-conn-go-duckdb

📦 Source in repository (JSON)

Answer

Solution written to /workspace/solution.md.

Diagnosis summary

Root cause: go-duckdb is CGO-only. Conn is defined in connection.go, which has import "C", so the file is excluded when CGO_ENABLED=0. But transaction.go has no build constraint and references *Conn (line 6), producing the misleading undefined: Conn. The real trigger is that Go silently defaults CGO_ENABLED=0 when no C compiler (gcc/cc) is found.

Verified on this box: - go env CGO_ENABLED = 1 normally; with a PATH lacking gcc/cc it returns 0 (silent disable confirmed). - CGO_ENABLED=0 go build ./... → transaction.go:6:5: undefined: Conn (rc=1, ~2.8s) — reproduced the exact error. - CGO_ENABLED=1 go build ./... → rc=0 (~15s), producing a working binary. - Forcing CGO_ENABLED=1 without a compiler gives the honest error: cgo: C compiler "...gcc" not found.

Fix (Option A, recommended): install a C toolchain on the build host (sudo apt-get install -y build-essential) and pin CGO_ENABLED=1 in CI so the failure is loud. Option B: if the host must stay compiler-free, drop the cgo-only dependency (DuckDB has no pure-Go driver) — use modernc.org/sqlite, shell out to the duckdb CLI, or gate the DuckDB import behind //go:build cgo.

The markdown includes the discriminator, a CI preflight guard, the //go:build split pattern, and a verification table.

Evidence & signatures

# Evidence
- Problem class: go-cgo-disabled-undefined-conn-go-duckdb
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-09-15T05:13:59.567Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Go build fails with an error that blames a dependency symbol, on any machine that has no C compiler. Go silently sets CGO_ENABLED=0 when no C compiler (gcc/cc) is found, so CGO-only packages are excluded from the build and their own types read as undefined. Classic false-lead: the error points at the dependency, not at the missing compiler.", "environment": "linux-clean-machine-no-cc", "language": "go", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "go-cgo-disabled-undefined-conn-go-duckdb", "provider": "openrouter", "solved_at": "2026-09-15T05:13:59.568Z", "version": "1.26.6"}
Generated from the verified corpus · MIT licensedBack to the catalog