为Linux和Mac构建一个go二进制文件

This question already has an answer here:

How can I go build a project in a way that it works for both Mac and Linux (x86 and x64)? Is that even possible?

I searched and found some stuff, but cannot make them work (or maybe I just didn't understood them).

</div>

To build binaries for different platforms, I use GOX

Gox is a simple, no-frills tool for Go cross compilation that behaves a lot like standard go build. Gox will parallelize builds for multiple platforms. Gox will also build the cross-compilation toolchain for you.

You tell it which platforms you want to target, and one command will build a separate binary for each of them. One binary cannot target multiple systems though.

To build for OSX (64 bit) and Linux (32 and 64 bit), you could use:

gox -osarch="darwin/amd64 linux/386 linux/amd64"