Every time I try to compile my program after (this morning) upgrading go from 1.1.1 to 1.1.2 (on Windows 7 64 bits), I get error message like:
C:\Users\VonC\prog\go\src\github.com\spf13\hugo>go build -o hugo.exe main.go
# github.com/spf13/hugo/hugolib
hugolib\page.go:23: import C:\Users\VonC\prog\go\pkg\windows_amd64/github.com/emicklei/hopwatch.a:
object is [windows amd64 go1.1.1 X:none]
expected [windows amd64 go1.1.2 X:none]
I tried a go clean -r
, but the error message persists?
What is the right clean
command to use?
Here’s the command you need to run to compile your Go project for a 64-bit Windows machine: In this scenario, GOOS is windows, and GOARCH is amd64 indicating a 64-bit architecture. If you need to support a 32-bit architecture, all you need to do is change GOARCH to 386.
You're using 8c, which is the c compiler. 8g will compile go, and 8l will link. The section "Compile packages and dependencies" now list go build as the way to compile in go. You still call 8g behind the scene, and the parameters you could pass to 8g are now passed with -gcflags. use go run to run the go program.
If the arguments are a list of .go files, build treats them as a list of source files specifying a single package. Notice that go build and go install differ from go run in that the first two state to expect package names as arguments, while the latter expects go files. However, the first two will also accept go files as go install does.
This means that a Go binary does not need system dependencies such as Go tooling to run on a new system, unlike other languages like Ruby, Python, or Node.js. Putting these executables in an executable filepath on your own system will allow you to run the program from anywhere on your system. This is called installing the program onto your system.
Actual solution:
I reproduced the issue with:
go.exe
directly (I didn't have %GOROOT%\bin
in my path)GOROOT
pointing to the previous 1.1.1 installation folder (I kept go 1.1.1 and 1.1.2 installed in separated folders).If you are sticking with the default go setup (ie: one C:\go
installation directory, and %GOROOT%\bin
in your PATH
), you won't see this error.
But if you do see this error:
%GOROOT%
is consistent with the go.exe
you are callinggo install -a
as explained below. The go clean
mentioned below won't be necessary.the Go build system is supposed to figure out any obsolete stuff in
$GOPATH/pkg
and (transitively) rebuild it on demand.
Original solution:
In the "Remove object files" section of "Command go" page, I missed the go clean -i
option:
-i
The
-i
flag causes clean to remove the corresponding installed archive or binary (what 'go install' would create).
And those .a
file (like hopwatch.a) are precisely what go install generates for libraries (in Windows).
So the full clean command, to make sure go rebuild everything, would be:
cd C:\Users\VonC\prog\go\src\github.com\spf13\hugo
go clean -r -i
go install -a
That will rebuild and install everything, including all dependent packages.
The -a
is actually a build option, which forces rebuilding of packages that are already up-to-date.
As usual, go clean -r -n
would show you what would be cleaned (-n
: preview option).
It doesn't hurt to be sure of what will be deleted... before actually deleting anything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With