我尝试运行以下 bar.go 脚本package mainimport ( "fmt" "syscall")func main() { fmt.Printf("%d\n", uintptr(syscall.ENONET))}通过调用go run bar.go并得到这个错误:# command-line-arguments./bar.go:9:29: undefined: syscall.ENONET我正在使用 Mac 和 go 版本1.14.3 darwin/amd64。我试图在 Go 操场上运行这个确切的脚本,https://play.golang.org/p/ecMZPsGgGOa并且它有效。我尝试使用运行脚本CGO_ENABLED=1 GOOS=linux GOARCH=amd64并收到此错误:fork/exec /var/folders/2l/dj6ph5t92y17vhtv3n6xzr5r0000gn/T/go-build847134732/b001/exe/bar: exec format error如何syscall.ENONET在 Mac 上工作?
1 回答

ibeautiful
TA贡献1993条经验 获得超5个赞
是的,它有一些奇怪的问题。虽然,系统调用现在被锁定了。
Deprecated: this package is locked down.
Callers should use the corresponding package in the golang.org/x/sys repository instead.
我试过了go version go1.14.3 darwin/amd64,但我遇到了同样的问题。
但是在文档中,我们有:
ENONET = Errno(0x40)
因为,Errno也是导出类型,您可以显式模拟相同的行为:
package main
import (
"fmt"
"syscall"
)
func main() {
fmt.Printf("%d\n", syscall.Errno(0x40)) // 64
fmt.Printf("%v\n", syscall.Errno(0x40)) // host is down
}
- 1 回答
- 0 关注
- 167 浏览
添加回答
举报
0/150
提交
取消