Golang: 无法使用 syscall.EpollCreate

huangapple go评论69阅读模式
英文:

Golang: Can't use syscall.EpollCreate

问题

我正在尝试将一个C程序移植到Go语言,所以需要使用syscall包中的很多内容。

我正在尝试使用https://pkg.go.dev/syscall#EpollCreate,但是VSCode拒绝为我自动补全它或者识别它是一个已定义的函数。值得一提的是,我可以为syscall包中的许多其他内容获得自动补全。

我的项目使用的是Go 1.14版本。我不确定如何确定哪个版本引入了哪些内容,所以我想知道这是否是我的问题。

我尝试创建了一个使用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)
}

</details>


# 答案1
**得分**: 0

原文翻译如下:

原来,如果你在开发一个与你自己不同的平台上,可能会有一些不支持的功能(比如这种情况下的`EpollCreate`,正如@JimB所说)。不过,Go扩展确实允许你更改环境变量,所以你可以在VSCode中解决这个问题。在你的扩展设置中,添加如下内容:

{
"go.toolsEnvVars": {"GOOS" : "linux"}
}


这样,你的项目将会为该操作系统进行构建。

设置文件可以在项目根目录下的`.vscode`文件夹中找到。如果没有这个文件夹,你可以进入VSCode中的Go扩展并调整一些设置(针对工作区,而不是用户),它会为你创建一个设置文件。然后根据需要进行编辑。

另请参考:https://github.com/microsoft/vscode-go/issues/632

<details>
<summary>英文:</summary>

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:

{
"go.toolsEnvVars": {"GOOS" : "linux"}
}

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&#39;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

</details>



huangapple
  • 本文由 发表于 2022年3月5日 03:15:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/71356231.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定