Reputation: 6252
I've used the Windows msi to install Go on my machine, but when I try to run a trivial Hello World
, like so:
go run hello.go
I get the following error:
hello.go:3:8: cannot find package "fmt" in any of: C:\Go\src\pkg\fmt (from $GOROOT)
In the GOROOT
this package can indeed not be found, since it's installed in the following directory:
C:\Go\src (missing the \pkg)
GOROOT
is set to C:\Go
(automatically), C\Go\bin
is added to the PATH
My GOPATH
is set to my workspace, but that doesn't seem to change anything.
How can this be fixed? Should I copy all packages to C:\Go\src\pkg
?
Did I do anything wrong?
EDIT
As requested by @Volker, here's the output of go env
:
set GOARCH=amd64
set GOBIN=
set GOCHAR=6
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\aage\gocode
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
Upvotes: 3
Views: 3233
Reputation: 1327364
Check your %PATH%
: I have multiple go versions installed and I see:
fmt
in %GOROOT%(1.3)\src\pkg
: C:\prgs\go\go1.3.2.windows-amd64\src\pkg\fmt\
fmt
in %GOROOT%(1.4)\src
: C:\prgs\go\go1.4.windows-amd64\src\fmt\
The sources have been reorganized.
See "Go 1.4 src/pkg → src
".
That means you might see that error if you are trying to compile with a go 1.3 while GOROOT
points to a Go1.4 installation.
If that doesn't work, uninstall, and use the go1.4.windows-amd64.zip
archive: unzip it anywhere you want, point GOROOT
to it, add GOROOT/bin
and everything should work.
Upvotes: 2