英文:
go build fails : runtime/mstkbar.go:151:10: debug.gcstackbarrieroff undefined
问题
这段代码在之前的golang版本(1.8.3)中编译通过,但在升级到新的golang版本(1.9)后无法编译。
任何想法吗?实际上,这个错误发生在任何golang版本升级时,不仅仅是我在这里提到的版本。
PS 当执行go get -v -t ./...
时也会出现相同的错误。
英文:
This code compiled OK using prior release of golang (1.8.3) however fails to compile after upgrading to new golang (1.9)
~/src/gopath/src/github.com/scottstensland/infosynth $ go build infosynth.go
# runtime
/usr/local/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)
/usr/local/go/src/runtime/mstkbar.go:162:24: division by zero
/usr/local/go/src/runtime/mstkbar.go:162:43: invalid expression unsafe.Sizeof(composite literal)
/usr/local/go/src/runtime/mstkbar.go:162:44: undefined: stkbar
/usr/local/go/src/runtime/mstkbar.go:212:4: gp.stkbar undefined (type *g has no field or method stkbar)
/usr/local/go/src/runtime/mstkbar.go:213:15: gp.stkbar undefined (type *g has no field or method stkbar)
/usr/local/go/src/runtime/mstkbar.go:216:23: undefined: stackBarrierPC
/usr/local/go/src/runtime/mstkbar.go:226:28: gp.stkbarPos undefined (type *g has no field or method stkbarPos)
/usr/local/go/src/runtime/mstkbar.go:227:19: gp.stkbarPos undefined (type *g has no field or method stkbarPos)
/usr/local/go/src/runtime/mstkbar.go:248:41: undefined: stkbar
/usr/local/go/src/runtime/mstkbar.go:227:19: too many errors
Any ideas ? Actually, this error happens for any golang version upgrade not just the versions I mentioned here.
PS Also get same errors when issuing : go get -v -t ./...
答案1
得分: 29
解决方案:在安装新的Go版本之前,您必须首先删除先前安装的Go。
输入以下命令以确认Go的位置:
type go
典型的输出为:
go is /usr/local/go/bin/go
删除/usr/local/go
而不仅仅是/usr/local/go/bin/go
,所以执行以下命令:
sudo rm -rf /usr/local/go
然后再安装新版本:
export golang_ver=$(curl https://golang.org/VERSION?m=text 2> /dev/null)
wget https://storage.googleapis.com/golang/${golang_ver}.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf ${golang_ver}.linux-amd64.tar.gz
英文:
SOLUTION : you must first delete previous golang install prior to installing new go version
type go # issue this to confirm where your go lives
a typical output :
go is /usr/local/go/bin/go # delete /usr/local/go not just /usr/local/go/bin/go
so just remove it
sudo rm -rf /usr/local/go # OP's missing step else above errors
before you install new version
export golang_ver=$(curl https://golang.org/VERSION?m=text 2> /dev/null)
wget https://storage.googleapis.com/golang/${golang_ver}.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf ${golang_ver}.linux-amd64.tar.gz
答案2
得分: 2
我使用的是Windows10操作系统。我必须使用控制面板卸载go18(当1.9安装程序要求卸载之前的版本时,不要相信它,手动卸载)。之后,我删除了默认的goroot路径c:\go,然后才安装1.9版本。在我的情况下,安装的是1.9.2版本。当然,还要检查你的GOROOT和GOPATH设置。
英文:
I use Windows10. I have to uninstall go18 with Control Panel (do not trust 1.9 installer when he asks to uninstall prev version - do it by hands). After that I remove c:\go - the default goroot and only after this - install 1.9. In my case it was 1.9.2
And of course check your GOROOT && GOPATH
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论