英文:
How to compile go program in 1.1.2 with dependencies compiled in 1.1.1?
问题
每次我尝试在升级了Go从1.1.1到1.1.2之后(在Windows 7 64位系统上)编译我的程序时,我都会收到如下的错误信息:
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]
我尝试了go clean -r
,但错误信息仍然存在。
正确的clean
命令是什么?
英文:
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?
答案1
得分: 4
实际解决方案:
我使用以下方法重现了这个问题:
- 直接调用1.1.2版本的
go.exe
(我的路径中没有%GOROOT%\bin
) - 将
GOROOT
指向之前安装的1.1.1版本的文件夹(我将go 1.1.1和1.1.2安装在不同的文件夹中)。
如果你使用的是默认的go设置(即:一个 C:\go
安装目录,并且%GOROOT%\bin
在你的PATH
中),你不会看到这个错误。
但是如果你确实看到了这个错误:
> Go构建系统应该能够找出$GOPATH/pkg
中的任何过时内容,并在需要时(传递地)重新构建它。
原始解决方案:
在“Command go”页面的“删除对象文件”部分,我忽略了go clean -i
选项:
-i
> -i
标志会导致clean删除相应的已安装的存档文件或二进制文件(即go install
会创建的文件)。
而那些.a
文件(如hopwatch.a)正是go install为库生成的文件(在Windows中)。
因此,完整的clean命令,以确保go重新构建所有内容,应该是:
cd C:\Users\VonC\prog\go\src\github.com\spf13\hugo
go clean -r -i
go install -a
这将重新构建和安装所有内容,包括所有依赖包。
-a
实际上是一个构建选项,它强制重新构建已经是最新版本的包。
通常情况下,go clean -r -n
会显示将要被清理的内容(-n
:预览选项)。
在实际删除任何内容之前,确保知道将要被删除的内容是没有坏处的。
英文:
Actual solution:
I reproduced the issue with:
- calling the 1.1.2
go.exe
directly (I didn't have%GOROOT%\bin
in my path) - with
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:
- make sure
%GOROOT%
is consistent with thego.exe
you are calling go install -a
as explained below. Thego clean
mentioned below won't be necessary.
As jnml comments:
> 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论