syscall variables undefined - go

When trying to build the following program on my Mac I get a build error: undefined: syscall.TCPInfo even though that variable is clearly documented http://golang.org/pkg/syscall/#TCPInfo
package main
import "syscall"
func main() {
_ = syscall.TCPInfo{}
}
Here is my go tool version.
$ go version
go version go1.3 darwin/amd64
I thought this might be an issue a lack of OS support so I tried it on http://play.golang.org, but it looks like many documented variables are just randomly missing from the syscall package: http://play.golang.org/p/w3Uk6NaZVy
Am I missing something?

The variable specified inside syscall are OS dependent.
you can add a suffix to the file to specify which os they should be built for:
// +build linux,386 darwin,!cgo
So you can use specific syscall flags for each OS.

Related

underfined function error in go :jmpToFunctionValue

While running main.go getting this error in monkey file and function is given below.
bou.ke/monkey
../go/pkg/mod/bou.ke/monkey#v1.0.2/replace.go:24:14: undefined: jmpToFunctionValue
Anyone help me with that?
I also face this error while using mac M1.
could you check the goarch var in go env? if you got arm64, you need to change it to amd64 using this command
go env -w GOARCH=amd64
it works for me

Build constraints exclude all Go files (macOS with Go 1.18.3) [duplicate]

This question already has an answer here:
golang build constraints exclude all Go files in
(1 answer)
Closed 8 months ago.
I am new to Go and terratest. I have the following terratest
package main
import (
"regexp"
"testing"
"github.com/gruntwork-io/terratest/modules/terraform"
"github.com/stretchr/testify/assert"
)
func TestS3Creation(t *testing.T) {
t.Parallel()
terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
TerraformDir: "./unit-test",
})
defer terraform.Destroy(t, terraformOptions)
terraform.InitAndApply(t, terraformOptions)
bastionSecurityGroup := terraform.Output(t, terraformOptions, "bastion_security_group")
assert.Regexp(t, regexp.MustCompile(`^sg-*`), bastionSecurityGroup)
}
I initialised it as follows:
go mod init github.com/myorg/terraform-bastion-linux
When trying to run it with go test -v I get the error:
package github.com/myorg/terraform-bastion-linux: build constraints exclude all Go files in /Users/george/terraform-bastion-linux/test
My environment is as follows:
macOS Big Sur 11.6.4
CPU: Intel i9
terraform --version
Terraform v1.2.3
on darwin_amd64
go version
go version go1.18.3 darwin/amd64
I have no env variables set that start with GO, for example, env|grep GO returns nothing as result.
As advised in:
build constraints exclude all Go files in
build constraints exclude all Go files
I have tried adding the following on top of the file
//+build darwin,cgo linux
//go:build (darwin && cgo) || linux
And also exporting the GOOS and GOARCH env variables
export GOOS=darwin
export GOARCH=amd64
But I still get the same error.
How to troubleshoot this issue?
What can I try in order to run the test successfully?
As commented by JimB, the problem was that the filename included the word linux, which Go interpreted as a build constraint to only run on Linux and not Darwin. I am new to Go, and it appears to be terribly misleading with such errors. I didn't even include the file name in my original question as I thought it would be irrelevant.

Trouble with go get install for mcumgr

I am trying to install MCUMgr on MACos. Here is a link for mcumgr: https://docs.zephyrproject.org/latest/services/device_mgmt/mcumgr.html
I install the Go Programming Language and enter this command:
go install github.com/apache/mynewt-mcumgr-cli/mcumgr#latest
Upon doing this I get the following error:
go/pkg/mod/golang.org/x/sys#v0.0.0-20200223170610-d5e6a3e2c0ae/unix/zsyscall_darwin_amd64.go:28:3: //go:linkname must refer to declared function or variable
I then googled and found the following from stackoverflow: Go 1.18 build error on Mac: "unix/syscall_darwin.1_13.go:25:3: //go:linkname must refer to declared function or variable"
This gives me the following error:
go: golang.org/x/sys: unrecognized import path "golang.org/x": parse https://golang.org/x?go-get=1: no go-import meta tags ()
I am stuck right now on how to install MCUMgr for MACos and wondering if someone has previously had the same issues?
I used go 1.17 instead and used:
go get github.com/apache/mynewt-mcumgr-cli/mcumgr
Then into the bin folder where it is installed use sudo ./mcumgr to run.

Undefined: syscall.Kill on Windows

I'm using eaburns/Watch library on a windows machine, but when trying to get the package with go get github.com/eaburns/Watch I get the following errors:
main.go:159: undefined: syscall.Kill
main.go:169: undefined: syscall.Wait4
main.go:169: undefined: syscall.WNOHANG
Any reason why this happens only on windows computers? How to fix this?
The syscall package is dependent on the operating system. syscall.Kill is for Unix/Linux/Mac systems, not Windows.
Use godoc syscall to get information on the syscall package for your system. This is explained in the Overview section in the package documentation:
https://golang.org/pkg/syscall/

go get sys: textflag.h missing

I am trying to use the "sys" package in a go program. So I did
go get golang.org/x/sys/unix
and got
# golang.org/x/sys/unix
src/golang.org/x/sys/unix/asm.s:6 6a: No such file or directory: textflag.h
I am on Fedora 20, using
go version go1.3.3 linux/amd64
Any ideas how to solve this?
The sys package was introduced as a replacement for syscall in go 1.4, I would assume that it doesn't work in versions prior to 1.4.
if you cannot upgrade, look at the syscall package to see if it meets your needs.

Resources