英文:
Is there a way to compile a x86-64 golang binary on 2021 m1 macbook pro?
问题
我正在考虑购买一台新的MacBook Pro,但有一件事让我犹豫不决,那就是我可能需要在这台机器上编译x86的Go语言二进制文件,并将其复制到其他x86机器上。我在Google上进行了一些搜索,似乎Go语言支持交叉编译,但有人有这方面的经验吗?我能否在M1 MacBook Pro上编译并获得一个可以在像Ubuntu 20.04这样的x86-64机器上运行的x86-64 Go语言二进制文件?
谢谢。
英文:
I am thinking of purchasing a new macbook pro, but one thing bothers me, which is that I may need to compile the x86 golang binary on this machine and copy it to the other x86 machines, I did some search on Google, and it seems that Go support cross-compile, but anyone has the experience with this before?
Can I compile and get a x86-64 golang binary on the m1 macbook pro, which can be runned on the x86-64 machines with system like Ubuntu 20.04?
Thanks.
答案1
得分: 5
我不认为苹果 M1 会给你带来任何问题。
Windows 编译:
GOOS=windows GOARCH=amd64 go build hello.go
Apple M1 编译:
GOOS=darwin GOARCH=arm64 go build -o hello-macos-arm64 hello.go
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论