在2021年的M1 MacBook Pro上编译x86-64的Golang二进制文件有办法吗?

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

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

dev.to 上有一篇很棒的博客文章。希望这对你有帮助。
链接

英文:

I don't think Apple M1 will cause you any problem . <br>
Compilation for Windows :

GOOS=windows GOARCH=amd64 go build hello.go

Compilation for Apple M1 :

GOOS=darwin GOARCH=arm64 go build -o hello-macos-arm64 hello.go

There is a great blog in dev.to . I hope this will be helpful
link

huangapple
  • 本文由 发表于 2022年1月26日 11:47:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/70858459.html
匿名

发表评论

匿名网友

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

确定