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
Here we can see that both in go env and system env, CGO_ENABLED=1 is set
akhil@akhil-ThinkPad-L14:~/W/d/golang-darwin-cgo $ GOOS=darwin go build main.go
# runtime/cgo
cgo: C compiler "clang" not found: exec: "clang": executable file not found in$PATH
and 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 unless export 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 about CGO_ENABLED and the above program should fail to compile always if CGO_ENABLED=1 is present in the go env.
When using go1.23.4, getting similar issue. i.e irrespective of whether the system env is set to CGO_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:
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
seankhliao
changed the title
CGO_ENABLED=1 is not considered if the env is not set via export.
cmd/go: implicit CGO_ENABLED=1 in go env can be misleading
Dec 16, 2024
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: