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

huangapple go评论115阅读模式
英文:

Go 1.9 gives runtime error on Windows 10

问题

我在Windows 10上安装了Go 1.9,并且当我运行一个名为'Hello World'的程序时,出现了以下错误。

# runtime
C:\Go\src\runtime\mstkbar.go:151:10: debug.gcstackbarrieroff未定义(类型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 }没有字段或方法gcstackbarrieroff)
C:\Go\src\runtime\mstkbar.go:162:24: 除零错误
C:\Go\src\runtime\mstkbar.go:162:43: 无效表达式unsafe.Sizeof(composite literal)
C:\Go\src\runtime\mstkbar.go:162:44: 未定义:stkbar
C:\Go\src\runtime\mstkbar.go:212:4: gp.stkbar未定义(类型*g没有字段或方法stkbar)
C:\Go\src\runtime\mstkbar.go:213:15: gp.stkbar未定义(类型*g没有字段或方法stkbar)
C:\Go\src\runtime\mstkbar.go:216:23: 未定义:stackBarrierPC
C:\Go\src\runtime\mstkbar.go:226:28: gp.stkbarPos未定义(类型*g没有字段或方法stkbarPos)
C:\Go\src\runtime\mstkbar.go:227:19: gp.stkbarPos未定义(类型*g没有字段或方法stkbarPos)
C:\Go\src\runtime\mstkbar.go:248:41: 未定义:stkbar
C:\Go\src\runtime\mstkbar.go:227:19: 错误太多

当我运行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
英文:

I installed Go 1.9 on Windows 10 and when I ran a class 'Hello World' program it gave me the following error.

# 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

When I ran go env, it gave me the following output,

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

得分: 3

在运行时出现没有明显原因的异常问题通常是由于在安装新版本之前未卸载先前版本引起的。

遗憾的是,Go的安装说明中没有提到这个问题。

一般来说,你应该移动或删除旧的Go安装,并从头开始安装新版本。

如果你是从源代码构建(就像我一样),最好将旧版本移动到不同的目录,然后配置一个临时环境,这样你就可以使用旧版本来构建新版本。如果是从官方二进制文件安装,只需删除旧版本即可。

无论你是如何安装的,都不应将自己的代码放在与运行时代码相同的目录中,因此,删除旧的运行时并重新安装/重建应始终是可行的。

英文:

Really weird issues in the runtime with no obvious cause are often caused by not uninstalling a pervious version before installing the new one.

Sadly the Go installation instructions make no mention of the issue.

In general you should move or delete your old Go install, and install the new version from scratch.

If you are building from source (the way I do) it is best to move the old version to a diferent directory, and then configure a temporary environment so you can use the old version to build the new one. If installing from the official binaries just deleting the old version is simplest.

Regardless of how you are installing you should never place your own code in the same tree as the runtime code, so just deleting the old runtime and reinstalling/rebuilding should always be possible.

huangapple
  • 本文由 发表于 2017年9月10日 23:33:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/46142440.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定