go: cmd/go: fails with `go: cannot find GOROOT directory` after cross-compiling from WSL to Windows.

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

$ GOROOT=/usr/local/go go version
go version go1.16.3 linux/amd64

Does this issue reproduce with the latest release?

No, building from go1.16.3 branch doesn’t reproduce this bug.

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

Using WSL 2 with Alpine Linux on Windows 10 Home, build 21364.co_release.210416-1504.

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/freya/.cache/go-build"
GOENV="/home/freya/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/freya/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/freya/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.3"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3203524129=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Cross-compiled Go toolchain master using Go 1.16.3 for windows/amd64, using the standard procedures as described on https://golang.org/doc/install/source. When running /mnt/c/Users/freya/goroot/bin/windows_amd64/go.exe version I got the following error instead: go: cannot find GOROOT directory: \mnt\c\Users\freya\goroot. The same happens when setting GOROOT=/mnt/c/Users/admer/goroot/.

What did you expect to see?

go.exe version running correctly and not failing.

What did you see instead?

% /mnt/c/Users/freya/goroot/bin/windows_amd64/go.exe version
go: cannot find GOROOT directory: \mnt\c\Users\freya\goroot
% GOROOT=/mnt/c/Users/freya/goroot/ /mnt/c/Users/freya/goroot/bin/windows_amd64/go.exe version
go: cannot find GOROOT directory: \mnt\c\Users\freya\goroot

About this issue

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

Most upvoted comments

What happens when you unset GOROOT? You normally do not have to set it as the default is dertermined by the executable location.

@rayjcwu go env GOROOT is set and detected by the go command and is only valid for the go command, the env var is not set for any other program. Do echo ${GOROOT} to print what golint sees

Since GOROOT is not set while running golint, it then defaults to the GOROOT that built it. i.e. /usr/local/Cellar/go/1.16.3/libexec

How do you run the Windows program? I think it is supposed to be run from Windows, not from the Linux environment.

WSL is not Windows.

If you want to use WSL environment, then you should follow Linux instructions on how to install and use Go.

If you want to use Windows environment, then you should follow Windows instructions for Go.

Alex