英文:
Go 1.18 build error on Mac: "unix/syscall_darwin.1_13.go:25:3: //go:linkname must refer to declared function or variable"
问题
我在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 必须引用已声明的函数或变量
../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/zsyscall_darwin_amd64.1_13.go:27:3:
//go:linkname 必须引用已声明的函数或变量
../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/zsyscall_darwin_amd64.1_13.go:40:3:
//go:linkname 必须引用已声明的函数或变量
../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/zsyscall_darwin_amd64.go:28:3:
//go:linkname 必须引用已声明的函数或变量
../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/zsyscall_darwin_amd64.go:43:3:
//go:linkname 必须引用已声明的函数或变量
../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/zsyscall_darwin_amd64.go:59:3:
//go:linkname 必须引用已声明的函数或变量
../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/zsyscall_darwin_amd64.go:75:3:
//go:linkname 必须引用已声明的函数或变量
../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/zsyscall_darwin_amd64.go:90:3:
//go:linkname 必须引用已声明的函数或变量
../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/zsyscall_darwin_amd64.go:105:3:
//go:linkname 必须引用已声明的函数或变量
../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/zsyscall_darwin_amd64.go:121:3:
//go:linkname 必须引用已声明的函数或变量
../../gopath/pkg/mod/golang.org/x/sys@v0.0.0-20200116001909-b77594299b42/unix/zsyscall_darwin_amd64.go:121:3:
错误太多
编译完成,退出码为2
英文:
I upgraded to Go 1.18 on Mac 12+.
'go build' fails with errors like:
# 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
答案1
得分: 346
这是由于golang.org/x/sys
的旧版本引起的(在此问题中提到)。修复方法是更新为:
go get -u golang.org/x/sys
英文:
This was caused by an old version of golang.org/x/sys
(mentioned in this issue). Fix is to update with:
go get -u golang.org/x/sys
答案2
得分: 7
根据文档提到的,有两种方式可以进行操作:
- 最简单的方式:运行
go get -u golang.org/x/sys
。 - 手动方式:将仓库克隆到
$GOPATH/src/golang.org/x/sys
。
英文:
As documentation mentioned,
- The easiest way : run
get -u golang.org/x/sys
. - Manual : git clone the repository to
$GOPATH/src/golang.org/x/sys
.
答案3
得分: 4
我遇到了同样的错误,并通过以下步骤进行了修复:
首先,我运行了以下命令:
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
。
英文:
I have faced same error and I fixed doing the following:
First I ran:
go get -u golang.org/x/sys
To update the x/sys
library.
Then it printed some important information:
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
With that in hands, I went to go.mod
and I have placed the following line (before the go 1.14
line):
replace golang.org/x/sys => golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e
And finally I ran:
go mod vendor
Then it updated all the libraries:
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
Then it was fine
❯ go install .
❯ terraform --version
Terraform v0.13.5
EDIT:
Here I am using modules
, if its not your case set GO111MODULE=off
.
答案4
得分: 2
如果go get -u golang.org/x/sys
无法工作,请确保在您的go.mod
文件中删除这一行:
replace golang.org/x/sys => golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6
英文:
If go get -u golang.org/x/sys
doesn't work, make sure to remove such line in your go.mod
:
replace golang.org/x/sys => golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6
答案5
得分: 0
请尝试这个,希望它能解决你的问题,就像解决我的问题一样:
sudo go get golang.org/x/sys@latest
英文:
Try this I hope it will solve your problem as mine:
sudo go get golang.org/x/sys@latest
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论