Golang在Win 10系统中运行和构建失败问题排查

Golang在Win 10系统中运行和构建失败问题排查 我安装了Go,设置了环境变量,运行 go version 后得到 go version go1.14 windows/amd64。我按照安装指南复制了“Hello World”程序,当我尝试运行 go run hello.go(hello.go 位于我当前使用的目录中)时,出现以下错误:

runtime/internal/atomic

…\runtime\internal\atomic\atomic_amd64x.go:13:6: Load redeclared in this block previous declaration at …\runtime\internal\atomic\atomic_amd64.go:16:24 …\runtime\internal\atomic\atomic_amd64x.go:19:6: Loadp redeclared in this block previous declaration at …\runtime\internal\atomic\atomic_amd64.go:22:32 …\runtime\internal\atomic\atomic_amd64x.go:25:6: Load64 redeclared in this block previous declaration at …\runtime\internal\atomic\atomic_amd64.go:28:26 …\runtime\internal\atomic\atomic_amd64x.go:30:6: Xadd redeclared in this block previous declaration at …\runtime\internal\atomic\atomic_amd64.go:39:37 …\runtime\internal\atomic\atomic_amd64x.go:33:6: Xadd64 redeclared in this block previous declaration at …\runtime\internal\atomic\atomic_amd64.go:42:39 …\runtime\internal\atomic\atomic_amd64x.go:36:6: Xadduintptr redeclared in this block previous declaration at …\runtime\internal\atomic\atomic_amd64.go:45:47 …\runtime\internal\atomic\atomic_amd64x.go:39:6: Xchg redeclared in this block previous declaration at …\runtime\internal\atomic\atomic_amd64.go:48:36 …\runtime\internal\atomic\atomic_amd64x.go:42:6: Xchg64 redeclared in this block previous declaration at …\runtime\internal\atomic\atomic_amd64.go:51:38 …\runtime\internal\atomic\atomic_amd64x.go:45:6: Xchguintptr redeclared in this block previous declaration at …\runtime\internal\atomic\atomic_amd64.go:54:45 …\runtime\internal\atomic\atomic_amd64x.go:48:6: And8 redeclared in this block previous declaration at …\runtime\internal\atomic\atomic_amd64.go:63:27 …\runtime\internal\atomic\atomic_amd64x.go:48:6: too many errors 当我执行 go build hello.go 时,出现同样的错误信息。我遗漏了什么?


更多关于Golang在Win 10系统中运行和构建失败问题排查的实战教程也可以访问 https://www.itying.com/category-94-b0.html

8 回复

刚刚试过了。同样的问题……

更多关于Golang在Win 10系统中运行和构建失败问题排查的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html


我再次卸载了Go,然后删除了Go文件夹中的所有文件,并重新开始安装。这次成功了。问题解决了,但不确定原因是什么…

go env 的输出是什么?你在 WSL 中也安装了 Go 吗?在 WSL 中运行 go env 的输出是什么?

出现的情况是你的两个安装以某种方式重叠了。你需要弄清楚为什么会这样。

太酷了!“问题解决了,但不确定原因……”这就是编程的艺术 😂 😂 编码愉快!

您的Go安装似乎出了问题。您是否将一个Go版本解压覆盖到了另一个版本之上?我建议您卸载后重新安装。

至少他写下了他所遵循的步骤帮助未来的Gopher们。

这个错误通常是由于Go安装目录中存在重复或损坏的文件导致的。以下是解决方案:

  1. 完全删除并重新安装Go
# 首先卸载Go
# 然后删除以下目录:
C:\Go
%USERPROFILE%\go
%USERPROFILE%\AppData\Local\go-build
%USERPROFILE%\AppData\Roaming\go
  1. 清理环境变量: 确保系统环境变量中只有以下Go相关变量:
GOROOT=C:\Go
GOPATH=%USERPROFILE%\go
PATH=%PATH%;C:\Go\bin;%USERPROFILE%\go\bin
  1. 重新安装后验证安装
go version
go env
  1. 创建并测试hello.go
package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}

运行测试:

go run hello.go
go build hello.go
./hello.exe
  1. 如果问题仍然存在,检查文件系统权限
# 以管理员身份运行命令提示符
go clean -cache
go clean -modcache

错误信息显示atomic_amd64x.goatomic_amd64.go中存在重复的函数声明,这表明Go运行时文件可能已损坏或存在版本冲突。完全重新安装通常可以解决此问题。

回到顶部