Go 1.9在Windows 10上发出运行时错误

时间:2017-09-10 15:33:24

标签: go

我在Windows 10上安装了Go 1.9,当我开设了一个班级' Hello World'程序它给了我以下错误。

# runtime
C:\Go\src\runtime\mstkbar.go:151:10: debug.gcstackbarrieroff undefined (type struct { allocfreetrace int32; cgocheck int32; efence int32; gccheckmark int32; gcpacertrace int32; gcshrinkstackoff int32; gcrescanstacks int32; gcstoptheworld int32; gctrace int32; invalidptr int32; sbrk int32; scavenge int32; scheddetail int32; schedtrace int32 } has no field or method gcstackbarrieroff)
C:\Go\src\runtime\mstkbar.go:162:24: division by zero
C:\Go\src\runtime\mstkbar.go:162:43: invalid expression unsafe.Sizeof(composite literal)
C:\Go\src\runtime\mstkbar.go:162:44: undefined: stkbar
C:\Go\src\runtime\mstkbar.go:212:4: gp.stkbar undefined (type *g has no field or method stkbar)
C:\Go\src\runtime\mstkbar.go:213:15: gp.stkbar undefined (type *g has no field or method stkbar)
C:\Go\src\runtime\mstkbar.go:216:23: undefined: stackBarrierPC
C:\Go\src\runtime\mstkbar.go:226:28: gp.stkbarPos undefined (type *g has no field or method stkbarPos)
C:\Go\src\runtime\mstkbar.go:227:19: gp.stkbarPos undefined (type *g has no field or method stkbarPos)
C:\Go\src\runtime\mstkbar.go:248:41: undefined: stkbar
C:\Go\src\runtime\mstkbar.go:227:19: too many errors

当我跑go env时,它给了我以下输出,

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\indu\go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config

1 个答案:

答案 0 :(得分:3)

运行时中没有明显原因的奇怪问题通常是由于在安装新版本之前没有卸载过去版本而引起的。

可悲的是the Go installation instructions没有提到这个问题。

通常,您应该移动或删除旧的Go安装,并从头开始安装新版本。

如果您从源代码构建(我的方式),最好将旧版本移动到不同的目录,然后配置临时环境,以便您可以使用旧版本来构建新版本。如果从官方二进制文件安装只是删除旧版本是最简单的。

无论您如何安装,都不应将自己的代码放在与运行时代码相同的树中,因此只需删除旧的运行时并重新安装/重建即可。