代码之家  ›  专栏  ›  技术社区  ›  Scott Stensland

go build失败:运行时/mstkbar。转到:151:10:调试。gcstackbarrieroff未定义

  •  13
  • Scott Stensland  · 技术社区  · 7 年前

    该代码使用golang(1.8.3)的早期版本编译正常,但升级到新的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
    

    附言 在发出以下命令时也会出现相同的错误:go get-v-t./。。。

    2 回复  |  直到 7 年前
        1
  •  29
  •   Scott Stensland    7 年前

    解决方案:在安装新的go版本之前,必须先删除以前安装的golang

    type go    # issue this to confirm where your go lives
    

    典型输出:

    go is /usr/local/go/bin/go  # delete /usr/local/go not just /usr/local/go/bin/go
    

    所以把它去掉

    sudo rm -rf /usr/local/go  #  OP's missing step else above errors
    

    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
  •   trashgenerator    7 年前

    我使用Windows10。我必须用控制面板卸载go18(当1.9安装程序要求卸载prev版本时,不要信任他-手动卸载)。在这之后,我删除了c:\go——默认的goroot,然后才安装1.9。在我的例子中是1.9.2 当然,检查一下你的GOROOT&&GOPATH公司