Reputation: 93934
I'm using golang 1.4.2 on Mac
I want to use Uname to get some information, followings are my codes:
package main
import (
"syscall"
)
func main() {
utsname := syscall.Utsname{}
syscall.Uname(&utsname)
}
But I got these errors:
# command-line-arguments
./main.go:8: undefined: syscall.Utsname
./main.go:9: undefined: syscall.Uname
Any went wrong?
Upvotes: 2
Views: 5182
Reputation: 5413
(Adding a more direct answer with exactly how I got past this problem)
Instead of importing syscall
, I imported golang.org/x/sys/unix
.
Then, the following code-block:
u := syscall.Utsname{}
syscall.Uname(&u)
is replaced by:
u := unix.Utsname{}
unix.Uname(&u)
NOTE! You need to call relevant functions for Windows.
Relevant contents of git diff
:
- "syscall"
+ "golang.org/x/sys/unix"
- utsname := syscall.Utsname{}
- syscall.Uname(&utsname)
+ utsname := unix.Utsname{}
+ unix.Uname(&utsname)
Upvotes: 2
Reputation: 19829
TL;DR Uname
and Utsname
are not available for OSX.
The reason is because those functions are not defined for the operating system.
Reading the documentation for syscall
this jumped at me:
The details vary depending on the underlying system, and by default, godoc will display the syscall documentation for the current system. If you want godoc to display syscall documentation for another system, set $GOOS and $GOARCH to the desired system.
Running godoc syscall
on my Mac yielded the sycall
documentation which does not include the Utsname
type nor the Uname
function call.
However, running GOOS=linux GOARCH=amd64 godoc syscall
actually shows the Utsname
and Uname
.
Also, note that the package itself is locked down in favor of OS specific packages
https://golang.org/pkg/syscall/ => https://godoc.org/golang.org/x/sys
Upvotes: 8