简体   繁体   中英

Go 1.18 build error on Mac: "unix/syscall_darwin.1_13.go:25:3: //go:linkname must refer to declared function or variable"

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

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

As documentation mentioned,

  1. The easiest way : run get -u golang.org/x/sys .
  2. Manual : git clone the repository to $GOPATH/src/golang.org/x/sys .

如果go get -u golang.org/x/sys不起作用,请确保在go.mod中删除这样的行:

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

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 .

$ git clone https://github.com/fullstorydev/grpcui
$ cd grpcui
$ go build ./...
$ cd cmd/grpcui
$ go install
$ grpcui -help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM