dri98076 2013-08-13 08:47
浏览 40
已采纳

如何在1.1.2中编译依赖项并在1.1.2中编译go程序?

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条回答 默认 最新

  • duanhuau567787 2013-08-13 08:47
    关注

    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 the go.exe you are calling
    • go install -a as explained below. The go 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?