Golang:无法使用syscall.EpollCreate
我正在尝试将程序从 C 移植到 Go,因此需要使用 syscall 包中的大量内容。
我正在尝试使用 https://pkg.go.dev/syscall#EpollCreate,但是VSCode 拒绝为我自动完成它或识别它是一个已定义的函数。 FWIW,我在 syscall 包中获得了许多其他内容的自动完成功能。
我的项目使用的是 Go 1.14。我不确定如何判断 Go 的版本是在哪个版本中引入的,所以我想知道这是否是我的问题。
我尝试创建一个使用 Go 1.17 的虚拟项目,但仍然没有成功。
我正在 Mac 上编写代码,但如果重要的话,它最终会针对 ARM Linux 进行编译。
那么这是 Go 问题还是 VSCode 问题?两个都?两者都不?
示例虚拟项目:
go.mod
:
module epoll-noodle
go 1.14
main.go
:
package main
import (
"syscall"
)
func main() {
syscall.EpollCreate(4)
}
I am trying to port a program from C to Go, so using a lot of stuff from the syscall
package is required.
I am trying to use https://pkg.go.dev/syscall#EpollCreate, but VSCode refuses to autocomplete it for me or recognize that it is a defined function. FWIW, I get autocomplete for many other things in the syscall
package.
My project is using Go 1.14. I am unsure how to tell what version of Go things were introduced in, so I am wondering if that is my problem.
I tried creating a dummy project that uses Go 1.17 and still no luck.
I am writing the code on a Mac, but it will eventually be compiled for ARM Linux, if that matters.
So is this a Go problem or a VSCode problem? Both? Neither?
Sample dummy project:
go.mod
:
module epoll-noodle
go 1.14
main.go
:
package main
import (
"syscall"
)
func main() {
syscall.EpollCreate(4)
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,如果您正在为与您自己的平台不同的平台进行开发,则某些功能可能不受支持(例如本例中的
EpollCreate
,正如 @JimB 所说)。不过,Go 扩展确实允许您更改环境变量,因此您可以在 VSCode 中解决此问题。在您的扩展设置中,输入类似以下内容:您的项目将为该操作系统构建。
设置文件可以在项目根目录的
.vscode
文件夹中找到。如果没有,您可以转到 VSCode 中的 Go 扩展并修改一些设置(针对工作区,而不是用户),它会为您创建一个。然后根据需要进行编辑。另请参阅:https://github.com/microsoft/vscode-go/issues/632
It turns out that if you are developing for a platform that differs from your own, some things may be unsupported (like
EpollCreate
in this case, as @JimB said). The Go extension does let you change your env vars though, so you can work around this in VSCode. In your extensions settings, put something like:and your project will be built for that OS.
The settings file can be found in the
.vscode
folder in the root of your project. If there isn't one, you can go to the Go extension in VSCode and fiddle with some settings (for the workspace, not the user) and it will create one for you. Then edit as necessary.See also: https://github.com/microsoft/vscode-go/issues/632