使用go run设置GOOS

时间:2016-04-20 18:07:39

标签: go

我目前正在开发一种可以构建为Windows服务或作为OSX / linux可执行文件运行的服务。

我在Windows文件上使用构建标记,包括使用main方法的文件

// +build windows

在另一个包含main方法的文件

// +build !windows

当我在mac端执行go run *.go时,出现以下错误

mainDOS.go:10:2: no buildable Go source files in /Users/michaelbrandenburg/Documents/git-repo/goCode/src/golang.org/x/sys/windows/svc
windowsService.go:15:2: no buildable Go source files in /Users/michaelbrandenburg/Documents/git-repo/goCode/src/golang.org/x/sys/windows/svc/debug
install.go:14:2: no buildable Go source files in /Users/michaelbrandenburg/Documents/git-repo/goCode/src/golang.org/x/sys/windows/svc/eventlog
install.go:15:2: no buildable Go source files in /Users/michaelbrandenburg/Documents/git-repo/goCode/src/golang.org/x/sys/windows/svc/mgr

有没有办法运行go run并定位我想要运行的架构?我可以毫无问题地构建可执行文件。

1 个答案:

答案 0 :(得分:1)

GOOS=darwin go run *.go将为Mac OSX设置env。虽然像JimB说的那样,但没有太多意义。通过

进行GOOS=darwin go build *.go是一种很好的交叉编译方式