Go版本升级后编译出错:Load redeclared in this block

今天打算把Go由1.11.4升级到1.15.2,升级的方法就两步,

先上Go官方下载页面( https://golang.org/dl/ )下载windows对应的压缩包

下载好后把压缩包解压到相应的目录:
覆盖安装就可以了
因为是升级,不是初次安装,之前已经把PATH设置好了,就不用管了。

之后执行以下命令,查看Go版本:

E:\GO2\src>go version
go version go1.15.2 windows/amd64

看到已经是1.15.2了,以为任务结束了。

但是用Go编译自己的程序,输出一大段如下错误:


# runtime/internal/atomic
C:\Go\src\runtime\internal\atomic\atomic_amd64x.go:13:6: Load redeclared in this block  
C:\Go\src\runtime\internal\atomic\atomic_amd64x.go:19:6: Loadp redeclared in this block
        previous declaration at C:\Go\src\runtime\internal\atomic\atomic_amd64.go:22:32
        previous declaration at C:\Go\src\runtime\internal\atomic\atomic_amd64.go:28:26
C:\Go\src\runtime\internal\atomic\atomic_amd64x.go:30:6: Xadd redeclared in this block
        previous declaration at C:\Go\src\runtime\internal\atomic\atomic_amd64.go:39:37
C:\Go\src\runtime\internal\atomic\atomic_amd64x.go:33:6: Xadd64 redeclared in this block        
        previous declaration at C:\Go\src\runtime\internal\atomic\atomic_amd64.go:42:39
C:\Go\src\runtime\internal\atomic\atomic_amd64x.go:36:6: Xadduintptr redeclared in this block   
        previous declaration at C:\Go\src\runtime\internal\atomic\atomic_amd64.go:45:47
        previous declaration at C:\Go\src\runtime\internal\atomic\atomic_amd64.go:48:36
C:\Go\src\runtime\internal\atomic\atomic_amd64x.go:42:6: Xchg64 redeclared in this block        
C:\Go\src\runtime\internal\atomic\atomic_amd64x.go:45:6: Xchguintptr redeclared in this block   
        previous declaration at C:\Go\src\runtime\internal\atomic\atomic_amd64.go:54:45
C:\Go\src\runtime\internal\atomic\atomic_amd64x.go:48:6: And8 redeclared in this block
        previous declaration at C:\Go\src\runtime\internal\atomic\atomic_amd64.go:63:27
C:\Go\src\runtime\internal\atomic\atomic_amd64x.go:48:6: too many errors

错误提示中说,atomic中的很多内容都重定义了,打开目录/go/src/runtime/internal/atomic下的atomic_amd64x.go和atomic_amd64.go,发现内容相近。

猜想可能新版本的源码文件名变更了,由于我们的新版本是直接解压过去的,导致老版本和新版本的源码文件同时存在。

所以直接不覆盖安装了,把老文件夹里的东西都删了,然后装新的。

之后用Go编译程序就没有错误了。

总结一下,安装Go时,如果选择安装在老版本目录,最好先把老版本完整删除掉。

  • 8
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值