'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/[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
Solution 1:[1]
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
Solution 2:[2]
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
.
Solution 3:[3]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | blackgreen |
Solution 2 | Henry |
Solution 3 | Stéphane Bruckert |