Search code examples
gosystem-callsepoll

Golang: Can't use syscall.EpollCreate


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)
}

Solution

  • 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'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