
// +build windows package main import ( "fmt" "syscall" "unsafe" ) var kernel32 = syscall.NewLazyDLL("kernel32.dll") var ( procGetCOnsoleMode= kernel32.NewProc("GetConsoleMode") ) // IsTerminal returns true if stderr's file descriptor is a terminal. func IsTerminal() bool { fd := syscall.Stderr var st uint32 r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, uintptr(fd), uintptr(unsafe.Pointer(&st)), 0) return r != 0 && e == 0 } func main() { fmt.Println("hello") } output:
→ go run main.go # command-line-arguments ./main.go:12: undefined: syscall.NewLazyDLL ./main.go:22: too many arguments in call to syscall.Syscall 放在独立的文件里是可以被编译的,但是放在 main 函数里面怎么就不可以。实在费解,可能我理解的是错的,请会的同学指出我的错误!
→ go build -x main.go WORK=/var/folders/68/kzwrnlkn3xzdlg8cjn2d0zm00000gp/T/go-build972181979 mkdir -p $WORK/command-line-arguments/_obj/ mkdir -p $WORK/command-line-arguments/_obj/exe/ cd /Users/admin/svn/src /usr/local/go/pkg/tool/darwin_amd64/compile -o $WORK/command-line-arguments.a -trimpath $WORK -p main -complete -buildid 37d5bca645f83d38f58c4de37fe5df48c9ced803 -D _/Users/admin/svn/src -I $WORK -pack ./main.go # command-line-arguments ./main.go:12: undefined: syscall.NewLazyDLL ./main.go:22: too many arguments in call to syscall.Syscall 1 defia 2017-02-06 23:48:16 +08:00 run 就直接 run 这个文件了吧 go build 才会忽略这个 |