gpt4 book ai didi

go - 使用 go run 设置 GOOS

转载 作者:数据小太阳 更新时间:2023-10-29 03:15:23 25 4
gpt4 key购买 nike

我目前正在开发一种服务,它可以构建为 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 并以我想要运行的架构为目标?我可以毫无问题地构建可执行文件。

最佳答案

GOOS=darwin go run *.go 将为 Mac OSX 设置环境。不过,正如 JimB 所说,这没什么意义。 GOOS=darwin go build *.go 是交叉编译的好方法

关于go - 使用 go run 设置 GOOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36751815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com