为了账号安全,请及时绑定邮箱和手机立即绑定

Go 1.18 在 Mac 上构建错误:

Go 1.18 在 Mac 上构建错误:

Go
慕妹3242003 2022-11-23 15:40:19

我在 Mac 12+ 上升级到 Go 1.18。


'go build' 失败并出现如下错误:


# golang.org/x/sys/unix

../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/syscall_darwin.1_13.go:25:3:

//go:linkname must refer to declared function or variable

../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/zsyscall_darwin_amd64.1_13.go:27:3:

//go:linkname must refer to declared function or variable

../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/zsyscall_darwin_amd64.1_13.go:40:3: 

//go:linkname must refer to declared function or variable

../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/zsyscall_darwin_amd64.go:28:3: 

//go:linkname must refer to declared function or variable

../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/zsyscall_darwin_amd64.go:43:3: 

//go:linkname must refer to declared function or variable

../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/zsyscall_darwin_amd64.go:59:3: 

//go:linkname must refer to declared function or variable

../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/zsyscall_darwin_amd64.go:75:3: 

//go:linkname must refer to declared function or variable

../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/zsyscall_darwin_amd64.go:90:3: 

//go:linkname must refer to declared function or variable

../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/zsyscall_darwin_amd64.go:105:3: 

//go:linkname must refer to declared function or variable

../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/zsyscall_darwin_amd64.go:121:3: 

//go:linkname must refer to declared function or variable

../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/zsyscall_darwin_amd64.go:121:3: 

too many errors


Compilation finished with exit code 2


查看完整描述

4 回答

?
汪汪一只猫

TA贡献1597条经验 获得超8个赞

这是由旧版本(本期golang.org/x/sys提到)引起的。修复是更新:

go get -u golang.org/x/sys


查看完整回答
反对 回复 2022-11-23
?
哔哔one

TA贡献1578条经验 获得超7个赞

文档所述,

  1. 最简单的方法:跑步get -u golang.org/x/sys

  2. 手动:git 将存储库克隆到$GOPATH/src/golang.org/x/sys.


查看完整回答
反对 回复 2022-11-23
?
湖上湖

TA贡献0条经验 获得超2个赞

我遇到了同样的错误,我固定执行以下操作:


首先我跑了:


go get -u golang.org/x/sys

更新x/sys图书馆。


然后它打印了一些重要信息:


go: downloading golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e

go: upgraded golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd => v0.0.0-20220704084225-05e143d24a9e

有了它,我去了go.mod并放置了以下行(行前go 1.14):


replace golang.org/x/sys => golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e

最后我跑了:


go mod vendor

然后它更新了所有库:


go: downloading github.com/hashicorp/go-cleanhttp v0.5.1

go: downloading github.com/hashicorp/go-rootcerts v1.0.0

go: downloading github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db

go: downloading github.com/mitchellh/cli v1.0.0

[...]

go: downloading github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db

go: downloading github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412

go: downloading github.com/Azure/go-autorest/autorest/to v0.4.0

然后就好了


❯ go install .

❯ terraform --version

Terraform v0.13.5

modules编辑:如果不是你的案例集,我在这里使用GO111MODULE=off。


查看完整回答
反对 回复 2022-11-23
?
HUX布斯

TA贡献1577条经验 获得超6个赞

如果go get -u golang.org/x/sys不起作用,请确保删除您的此类行go.mod

replace golang.org/x/sys => golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6


查看完整回答
反对 回复 2022-11-23

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信