英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论