You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docker pull debian:12.7
docker run -it debian:12.7
apt update
apt -y install wget
wget https://go.dev/dl/go1.23.0.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.23.0.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
mkdir src &&cd src
go mod init example
cat <<EOF > main.gopackage mainimport "C"func main() {}EOF
go mod tidy
go build
What did you see happen?
# go build
package example: build constraints exclude all Go files in /src
What did you expect to see?
go build should produce a better error message indicating what happened. It's not obvious what build constraints exist, or why they could not be satisfied. No amount of go build -v, go build -x, or go build -work. The only hint that something is wrong is in go env, namely CGO_ENABLED=0.
https://pkg.go.dev/cmd/cgo does explain that cgo produces a build constraint, and even goes on to explain that CGO_ENABLED=0 is set if the default C compiler is not found (or CC is unset). This makes sense, as the container in this bug report (intentionally) did not (yet) have gcc/clang installed. Even setting CC=/bin/true makes go build -x show it actually trying to compile things, as opposed to giving a confusing error message.
Google searching for this error message returns results like this StackOverflow post that imply this is a corrupted module cache, which is not the right breadcrumb here.
It would be nice if go build could print a more detailed error message, perhaps special-casing cgo, if CGO_ENABLED=0 is set implicitly by a lack of present CC.
Note that this issue is not limited to the reduced reproduction case I provided here; I originally saw it when trying to go run a package that transitively depends on a go module that itself uses cgo:
# go run cmd/cli/main.go
github.com/msteinert/pam/v2: build constraints exclude all Go files in /root/go/pkg/mod/github.com/msteinert/pam/[email protected]
The text was updated successfully, but these errors were encountered:
Go version
go1.23.0 linux/amd64
Output of
go env
in your module/workspace:What did you do?
What did you see happen?
What did you expect to see?
go build
should produce a better error message indicating what happened. It's not obvious what build constraints exist, or why they could not be satisfied. No amount ofgo build -v
,go build -x
, orgo build -work
. The only hint that something is wrong is ingo env
, namelyCGO_ENABLED=0
.https://pkg.go.dev/cmd/cgo does explain that cgo produces a build constraint, and even goes on to explain that CGO_ENABLED=0 is set if the default C compiler is not found (or CC is unset). This makes sense, as the container in this bug report (intentionally) did not (yet) have gcc/clang installed. Even setting
CC=/bin/true
makesgo build -x
show it actually trying to compile things, as opposed to giving a confusing error message.Google searching for this error message returns results like this StackOverflow post that imply this is a corrupted module cache, which is not the right breadcrumb here.
It would be nice if
go build
could print a more detailed error message, perhaps special-casing cgo, ifCGO_ENABLED=0
is set implicitly by a lack of present CC.Note that this issue is not limited to the reduced reproduction case I provided here; I originally saw it when trying to
go run
a package that transitively depends on a go module that itself uses cgo:The text was updated successfully, but these errors were encountered: