2017-09-01 34 views
7

該代碼使用golang(1.8.3)的以前版本編譯OK但是無法升級到新的golang(1.9)去構建失敗:運行/ mstkbar.go:151:10:debug.gcstackbarrieroff未定義

之後編譯
~/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 

有什麼想法?實際上,這個錯誤發生在任何golang版本升級,而不僅僅是我在這裏提到的版本。

PS發行時,也得到同樣的錯誤:去拿-v -t/...

回答

21

解決方案:必須先刪除以前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 
1

我使用Windows10之前。我必須使用控制面板卸載go18(當他要求卸載prev版本時,不要信任1.9安裝程序 - 手動執行)。之後,我刪除c:\ go - 默認goroot,並且只有在此之後 - 安裝1.9。在我的情況下,它是1.9.2 當然,檢查你的GOROOT & & GOPATH