-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/go: implicit CGO_ENABLED=1 in go env can be misleading #70868
Comments
CGO_ENABLED=1
is not considered if the env is not set via export.
When you cross-compile, by changing This is documented at https://pkg.go.dev/cmd/cgo: search for CGO_ENABLED on that page. |
This is working as intended. See Ian's explanation in the comment above. You're checking
So, as Ian explained, setting GOOS affects the value of CGO_ENABLED. |
Go version
go version go1.22.10 linux/amd64
Output of
go env
in your module/workspace:What did you do?
CGO_ENABLED=1
in the go env and is unset in the system env. If we try to compile the program now, it works fineCGO_ENABLED
variable and then perform the compilation, it results in error.Here we can see that both in go env and system env,
CGO_ENABLED=1
is setand results in the above error when compiled which is expected since I dont have clang installed in my path.
What did you see happen?
Even if
CGO_ENABLED=1
is set in the go env, it doesnt come into effect unlessexport CGO_ENABLED=1
is used and it is set in the system env also.What did you expect to see?
go env
should give the correct information aboutCGO_ENABLED
and the above program should fail to compile always ifCGO_ENABLED=1
is present in the go env.go1.23.4
, getting similar issue. i.e irrespective of whether the system env is set toCGO_ENABLED=1
or not, the program always compiles, which should not happen as cross compilation to darwin should fail since clang is not present. Checked the 1.23.0 release notes and didnt see any specific mention of changes to compiler or linker related to cross compiling to darwin.The text was updated successfully, but these errors were encountered: