猿问

使用 go run 设置 GOOS

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


我在 Windows 文件上使用构建标记,包括带有主要方法的标记


// +build windows

而在另一个包含主要方法的文件上


// +build !windows

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


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和定位我想要运行的架构?我可以毫无问题地构建可执行文件。


Cats萌萌
浏览 562回答 1
1回答

万千封印

GOOS=darwin go run *.go将为 Mac OSX 设置 env。不过,就像 JimB 所说的那样,没有多大意义。GOOS=darwin go build *.go尽管这样做是交叉编译的好方法
随时随地看视频慕课网APP

相关分类

Python
我要回答