Bug 215603 - go1.18 defaults to CGO_ENABLED=0
Summary: go1.18 defaults to CGO_ENABLED=0
Alias: None
Product: Tools
Classification: Unclassified
Component: libcap (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: Andrew G. Morgan
Depends on:
Reported: 2022-02-14 03:17 UTC by Andrew G. Morgan
Modified: 2022-04-10 15:20 UTC (History)
0 users

See Also:
Kernel Version: n/a
Tree: Mainline
Regression: No


Description Andrew G. Morgan 2022-02-14 03:17:21 UTC
I've been experimenting with the go1.18 build tree ( to try to resolve https://github.com/golang/go/issues/50113 ) and it would appear that this version of GO has returned to CGO_ENABLED=0 being the default build mode.

This causes the libcap/go/compare-cap.go build test to fail:

$ make GO=~/gohacks/go/bin/go clean -C go compare-cap
go: no Go source files
make: *** [Makefile:58: compare-cap] Error 1

$ cd go
$ make GO=~/gohacks/go/bin/go all test
[failure again, but dependencies set up..]
$ CGO_ENABLED=1 CC="gcc"  CGO_CFLAGS="-I$HOME/gits/libcap/libcap/include/uapi -I$HOME/gits/libcap/libcap/include" CGO_LDFLAGS="-L$HOME/gits/libcap/libcap" ~/gohacks/go/bin/go build  -mod=vendor compare-cap.go

That is, if I force CGO_ENABLED=1 the compilation work.

$ go version ; go env CGO_ENABLED
go version go1.16.13 linux/amd64
$ ~/gohacks/go/bin/go version ; ~/gohacks/go/bin/go env CGO_ENABLED
go version devel go1.18-7fa52d74f2 Sun Feb 13 13:42:41 2022 -0800 linux/amd64
Comment 2 Andrew G. Morgan 2022-04-10 15:20:21 UTC
For the record, the setup was slightly different. The Go team have not changed the default build characteristics of Go to CGO_ENABLED=0. Instead, I was building the Go build tree with that configuration (to run its in-build tests with CGO_ENABLED=0), and that causes the built compiler to default to CGO_ENABLED=0.

Note You need to log in before you can comment on or make changes to this bug.