go: cmd/go: build fails requiring C compiler for runtime/cgo

What version of Go are you using (go version)?

I am running go 1.16.5, but I am also testing go 1.17rc1:

$ go1.17rc1 version
go version go1.17rc1 linux/amd64
$ go version
go version go1.16.5 linux/amd64

Does this issue reproduce with the latest release?

It’s ok with the latest stable release (1.16.5), not with 1.17rc1

What operating system and processor architecture are you using (go env)?

GOARCH=“amd64” GOOS=“linux” I am running Archlinux, fully up to date as of July 15 2021, 10:15 BST. I am running in an LXD container (LXD 4.16)

go env Output
$ go1.17rc1 env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/unix/.cache/go-build"
GOENV="/home/unix/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/unix/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/unix/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/unix/sdk/go1.17rc1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/unix/sdk/go1.17rc1/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17rc1"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build640958217=/tmp/go-build -gno-record-gcc-switches"

What did you do?

This is the full script of what I ran:

I [unix@go117 foo]$ go1.17rc1 mod init foo
go: creating new go.mod: module foo
I [unix@go117 foo]$ ed main.go
main.go: No such file or directory
a
package main

import ( 
  . "github.com/lyderic/tools"
)

func main(){
  Cyanln("Hello, World!")
}
.
wq
98
I [unix@go117 foo]$ go1.17rc1 mod tidy
go: finding module for package github.com/lyderic/tools
go: downloading github.com/lyderic/tools v0.3.4
go: found github.com/lyderic/tools in github.com/lyderic/tools v0.3.4
go: downloading github.com/fatih/color v1.10.0
go: downloading github.com/sendgrid/sendgrid-go v3.10.0+incompatible
go: downloading github.com/wayneashleyberry/terminal-dimensions v1.0.0
go: downloading github.com/mattn/go-colorable v0.1.8
go: downloading github.com/mattn/go-isatty v0.0.12
go: downloading github.com/sendgrid/rest v2.6.4+incompatible
go: downloading github.com/stretchr/testify v1.7.0
go: downloading golang.org/x/sys v0.0.0-20210423082822-04245dca01da
go: downloading golang.org/x/net v0.0.0-20210614182718-04defd469f4e
go: downloading github.com/davecgh/go-spew v1.1.0
go: downloading github.com/pmezard/go-difflib v1.0.0
go: downloading gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
I [unix@go117 foo]$ go1.17rc1 build
\# runtime/cgo
cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in $PATH
I [unix@go117 foo]$ go build
I [unix@go117 foo]$ ./foo
Hello, World!

What did you expect to see?

With go 1.16.5, the above program compiles with no error. I use only one external lib: github.com/lyderic/tools

What did you see instead?

With go 1.17rc1, I get the following error:

$ go1.17rc1 build # runtime/cgo cgo: C compiler “gcc” not found: exec: “gcc”: executable file not found in $PATH

Note: if I install gcc, the error (obviously) goes away. However, the program compiles with no gcc installed if I compile with go 1.16.5, so there might be a bug.

Thanks L.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 15 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Closing as a duplicate of #33840. #37158, #27303, #26988 are also related.

We need a much better diagnostic here, and we should reconsider whether CGO_ENABLED should default to 1 when no C compiler is installed.