构建错误:Mac 上 Go 1.18 报错 "unix/syscall_darwin.1_13.go:25:3: //go:linkname 必须引用声明的函数或变量"

时间:2024-02-19

浏览:382

作者:佚名

最近发现不少小伙伴都对Golang很感兴趣,所以今天继续给大家介绍Golang相关的知识,本文《构建错误:Mac 上 Go 1.18 报错 "unix/syscall_darwin.1_13.go:25:3: //go:linkname 必须引用声明的函数或变量"》主要内容涉及到等等知识点,希望能帮到你!当然如果阅读本文时存在不同想法,可以在评论中表达,但是请勿使用过激的措辞~

问题内容

我在 mac 12+ 上升级到 go 1.18。

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

# golang.org/x/sys/unix
../../gopath/pkg/mod/golang.org/x/[email protected]/unix/syscall_darwin.1_13.go:25:3:
//go:linkname must refer to declared function or variable
../../gopath/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.1_13.go:27:3:
//go:linkname must refer to declared function or variable
../../gopath/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.1_13.go:40:3: 
//go:linkname must refer to declared function or variable
../../gopath/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:28:3: 
//go:linkname must refer to declared function or variable
../../gopath/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:43:3: 
//go:linkname must refer to declared function or variable
../../gopath/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:59:3: 
//go:linkname must refer to declared function or variable
../../gopath/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:75:3: 
//go:linkname must refer to declared function or variable
../../gopath/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:90:3: 
//go:linkname must refer to declared function or variable
../../gopath/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:105:3: 
//go:linkname must refer to declared function or variable
../../gopath/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:121:3: 
//go:linkname must refer to declared function or variable
../../gopath/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:121:3: 
too many errors

Compilation finished with exit code 2


正确答案


这是由 golang.org/x/sys 的旧版本引起的(在 this issue 中提到)。修复方法是更新:

go get -u golang.org/x/sys

到这里,我们也就讲完了《构建错误:Mac 上 Go 1.18 报错 "unix/syscall_darwin.1_13.go:25:3: //go:linkname 必须引用声明的函数或变量"》的内容了。个人认为,基础知识的学习和巩固,是为了更好的将其运用到项目中,欢迎关注golang学习网公众号,带你了解更多关于的知识点!

本文内容来源于互联网,如有侵权请联系删除。

相关文章

更多

热门专题

更多
首页