如何在Apple Silicon Mac上构建适用于Windows的Go可执行文件

huangapple go评论101阅读模式
英文:

How to build Go Executables for windows from Apple Silicon Mac

问题

我有一台搭载m1芯片的新MacBook。

我想从一个main.go文件中创建一个Windows可执行文件。它内部使用了几个外部库。我可以使用命令go build main.go来构建适用于m1处理器的可执行文件。

但是,当我尝试使用命令env GOOS=windows GOARCH=amd64 go build main.go来构建Windows可执行文件时,它会失败并显示build constraints exclude all Go files

dilipyadav@Dilips-MacBook-Pro-2 isengard % pwd
/Users/dilipyadav/githome/my-project/cmd/isengard
dilipyadav@Dilips-MacBook-Pro-2 isengard % ls
main.go
dilipyadav@Dilips-MacBook-Pro-2 isengard % env GOOS=windows GOARCH=amd64 go build main.go
package command-line-arguments
	imports fyne.io/fyne/v2/app
	imports fyne.io/fyne/v2/internal/driver/glfw
	imports fyne.io/fyne/v2/internal/painter/gl
	imports github.com/go-gl/gl/v3.2-core/gl: build constraints exclude all Go files in /Users/dilipyadav/go/pkg/mod/github.com/go-gl/gl@v0.0.0-20190320180904-bf2b1f2f34d7/v3.2-core/gl
package command-line-arguments
	imports github.com/gordonklaus/portaudio: build constraints exclude all Go files in /Users/dilipyadav/go/pkg/mod/github.com/gordonklaus/portaudio@v0.0.0-20200911161147-bb74aa485641
dilipyadav@Dilips-MacBook-Pro-2 isengard %

我正在遵循这里的构建文档。

对于错误信息build constraints exclude all Go files,我查看了https://stackoverflow.com/questions/55348458/build-constraints-exclude-all-go-files-in。

非常感谢您的帮助。

英文:

I have a new MacBook with an m1 chip.

I want to make an windows executable file from a main.go file. Internally it uses couple of external libraries. I am able to build executable for m1 processor using the command go build main.go.

But when I try to build windows executable using command env GOOS=windows GOARCH=amd64 go build main.go, it fails with build constraints exclude all Go files

dilipyadav@Dilips-MacBook-Pro-2 isengard % pwd
/Users/dilipyadav/githome/my-project/cmd/isengard
dilipyadav@Dilips-MacBook-Pro-2 isengard % ls
main.go
dilipyadav@Dilips-MacBook-Pro-2 isengard % env GOOS=windows GOARCH=amd64 go build main.go
package command-line-arguments
	imports fyne.io/fyne/v2/app
	imports fyne.io/fyne/v2/internal/driver/glfw
	imports fyne.io/fyne/v2/internal/painter/gl
	imports github.com/go-gl/gl/v3.2-core/gl: build constraints exclude all Go files in /Users/dilipyadav/go/pkg/mod/github.com/go-gl/gl@v0.0.0-20190320180904-bf2b1f2f34d7/v3.2-core/gl
package command-line-arguments
	imports github.com/gordonklaus/portaudio: build constraints exclude all Go files in /Users/dilipyadav/go/pkg/mod/github.com/gordonklaus/portaudio@v0.0.0-20200911161147-bb74aa485641
dilipyadav@Dilips-MacBook-Pro-2 isengard %

I am following the build document from here

For the error build constraints exclude all Go files, I checked https://stackoverflow.com/questions/55348458/build-constraints-exclude-all-go-files-in.

Any help is highly appreciated.

答案1

得分: 3

请在您的项目主文件夹中运行以下命令(即存在 main.go 文件的文件夹):

GOOS=windows GOARCH=amd64 go build -o output_name.exe

这将在您的项目主文件夹中生成一个名为 output_name.exe 的可执行文件。

英文:

run this inside your project main folder (where main.go exists)

GOOS=windows GOARCH=amd64 go build -o output_name.exe

huangapple
  • 本文由 发表于 2021年6月14日 17:44:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/67968051.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定