Not planned
Description
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
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
AlexRouSg commentedon Apr 25, 2021
What happens when you unset
GOROOT
? You normally do not have to set it as the default is dertermined by the executable location.aodhneine commentedon Apr 25, 2021
Same as when
GOROOT
is set. Tried withGOROOT= /mnt/...
,export GOROOT=
, andunset GOROOT
.[-]Fails with `go: cannot find GOROOT directory` after cross-compiling from Linux to Windows.[/-][+]Fails with `go: cannot find GOROOT directory` after cross-compiling from WSL to Windows.[/+]AlexRouSg commentedon Apr 25, 2021
The path
/mnt/c/Users/freya/goroot/bin/windows_amd64/go.exe
looks like you are running inside WSL, which is weird cause you are trying to run a.exe
.Can you run it through powershell?
aodhneine commentedon Apr 26, 2021
It returns the exactly same error.
Let me try to clarify what I exactly did. First, I cloned Go repo to
C:\Users\freya\goroot
, since I cannot build it in WSL, as it requires support for LockFileEx, which isn't currently supported (see #37461 and microsoft/WSL#5762). Then I downloaded Go 1.16.3 release for Linux to/usr/local/go
in WSL, and added it to the PATH. Lastly, I went to thegoroot
folder and ranGOOS=windows GOARCH=amd64 ./all.bash
, building the Windows version of the compiler. When I ranbin/windows_amd64/go.exe
, it failed with that error.cherrymui commentedon Apr 26, 2021
How do you run the Windows program? I think it is supposed to be run from Windows, not from the Linux environment.
[-]Fails with `go: cannot find GOROOT directory` after cross-compiling from WSL to Windows.[/-][+]cmd/go: fails with `go: cannot find GOROOT directory` after cross-compiling from WSL to Windows.[/+]aodhneine commentedon Apr 26, 2021
WSL allows to transparently run Windows programs from the Linux environment.
AlexRouSg commentedon Apr 26, 2021
And I am asking whether it runs in a normal power shell, this is importatnt to know whether it is a WSL specific problem.
aodhneine commentedon Apr 26, 2021
As I previously wrote, it returns the same error.
AlexRouSg commentedon Apr 26, 2021
Was
GOROOT
unset while running in power shell?Did you try setting
GOROOT=C:/Users/freya/goroot
cherrymui commentedon Apr 26, 2021
Could you provide the exact commands that you use to build the toolchain, as well as how you run it? Thanks.
cherrymui commentedon Apr 26, 2021
cc @alexbrainman
aodhneine commentedon Apr 26, 2021
... Why does it work now?
AlexRouSg commentedon Apr 26, 2021
Did you change from WSL1 to WSL2?
aodhneine commentedon Apr 26, 2021
No, it was WSL2 before too.
alexbrainman commentedon Apr 28, 2021
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
rayjcwu commentedon May 10, 2021
I encountered this issue when trying to do cross-compiling
golint
from mac to Linux.On my mac, it has
, and I run
GOOS=linux go build
to build and upload the binary to LinuxOn my Linux box, it has
. But when I run the above binary, it shows
rather than picking up the go env GOROOT on Linux. It seems somehow the
GOROOT
info on my mac is baked into the binary.go env of my mac
OutputMore context here https://gophers.slack.com/archives/C0VPK4Z5E/p1620506869256300
AlexRouSg commentedon May 10, 2021
@rayjcwu
GOROOT
is being detected herehttps://github.com/golang/lint/blob/83fdc39ff7b56453e3793356bcff3070b9b96445/golint/import.go#L27
https://golang.org/pkg/runtime/#GOROOT
So your issue seems unrelated since the env var would not be set when running
./golint
unless you did so manually.rayjcwu commentedon May 10, 2021
Let me update my above comment. Here is my environment:
mac:
I run
GOOS=linux go build
and upload the binary to LinuxLinux:
. But when I run the above binary, it shows
go: cannot find GOROOT directory: /usr/local/Cellar/go/1.16.3/libexec
, rather than pick up thego env GOROOT
on Linux.AlexRouSg commentedon May 10, 2021
@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 whatgolint
seesSince
GOROOT
is not set while runninggolint
, it then defaults to theGOROOT
that built it. i.e./usr/local/Cellar/go/1.16.3/libexec
rayjcwu commentedon May 10, 2021
echo $GOROOT
is empty in both mac and Linux.Got it, thanks. This is what I missed.
seankhliao commentedon Jun 12, 2022
Looks like there is no bug here