Skip to content
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: go test complains about missing gcc (even if no tests exist, and only for certain imports) #27303

Closed
jhinrichsen opened this issue Aug 28, 2018 · 9 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@jhinrichsen
Copy link

Please answer these questions before submitting your issue. Thanks!

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

go version go1.11 linux/amd64

Does this issue reproduce with the latest release?

Yes, 1.11 is the latest release.

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jot/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jot/go"
GOPROXY=""
GORACE=""
GOROOT="/home/jot/bin/go"
GOTMPDIR=""
GOTOOLDIR="/home/jot/bin/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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-build025056307=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Create an empty directory, and copy a single main.go file.

Working: https://play.golang.org/p/sctz4PAGjf1
Breaking: https://play.golang.org/p/aZu1NZdtXel

Run go test

What did you expect to see?

The working main.go file shows the expected message [no test files].

What did you see instead?

The breaking main.go shows the error message

# runtime/cgo exec: "gcc": executable file not found in $PATH

Go 1.10.4 shows the correct message. Setting CGO_ENABLED="0" also leads to the correct message.

Using debian 9 (stretch) in a Windows Linux Subsystem.

@ianlancetaylor
Copy link
Contributor

Most likely a dup of #26988 and/or #27285.

@ianlancetaylor ianlancetaylor changed the title go test complains about missing gcc (even if no tests exist, and only for certain imports) cmd/go: go test complains about missing gcc (even if no tests exist, and only for certain imports) Aug 29, 2018
@FiloSottile FiloSottile added this to the Go1.12 milestone Aug 30, 2018
@FiloSottile FiloSottile added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 30, 2018
@palsivertsen
Copy link

Shouldn't this be part of Go1.11.1? Or are there any workarounds?

Running a CI pipeline is problematic when go test fails on the simplest of files:

package foo
import  _ "net/http"

@ianlancetaylor
Copy link
Contributor

This problem has been reported several times in several different bugs. We should probably try to concentrate on one issue. CC @bcmills

@bcmills
Copy link
Contributor

bcmills commented Sep 13, 2018

I'm starting with #27285 because it's easy to reproduce and leads to similar symptoms. I plan to recheck this issue once that one is resolved, in case the underlying cause is the same for both.

@bcmills
Copy link
Contributor

bcmills commented Sep 17, 2018

Pretty sure this one in particular is a dup of #26988.

@bcmills bcmills closed this as completed Sep 17, 2018
@jkomyno
Copy link

jkomyno commented Jun 24, 2019

Setting the environment variable CGO_ENABLED to 0 fixed it for me.

If you use docker, insert the following before your RUN go test or RUN go build operation:

ENV CGO_ENABLED 0

@cespedes
Copy link

cespedes commented Aug 26, 2019

Pretty sure this one in particular is a dup of #26988.

It's not :(

With go version go1.12.7 linux/amd64, "go build" does not need gcc, but "go test" does.

Having a directory with just one file, "foo.go", with just the lines:

package foo
import _ "net"

results in:

$ go test
# runtime/cgo
exec: "gcc": executable file not found in $PATH

@blafasel42
Copy link

ENV CGO_ENABLED 0 solved it for me

@wojnosystems
Copy link

Setting the environment variable CGO_ENABLED to 0 fixed it for me.

If you use docker, insert the following before your RUN go test or RUN go build operation:

ENV CGO_ENABLED 0

This also worked for me, but I did:

RUN CGO_ENABLED=0 go test -run="" /tmp/build/pkg/*

To avoid setting an environment variable.

Thanks jkomyno

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

10 participants