我目前正在开发一个可以构建为windows服务或以OSX/linux可执行文件运行的服务。使用go run设置GOOS
我使用的是Windows上构建的文件标签,包括一个与主方法
// +build windows
,并在含有main方法
// +build !windows
其他文件。当我在执行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
并针对我想运行的体系结构?我可以毫无问题地构建可执行文件。
用'go run'设置GOOS没有意义,因为'go run'是为了立即在主机操作系统上执行。 – JimB
或者您可能对“构建约束”感到困惑? 'go run'不遵循构建约束,因为你已经明确列出了构建参数的文件。你不应该使用'go run'来进行简单的测试,并且你可以使用'go install'和'go build'来处理完整的包。 – JimB