2

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).

caarlos0
  • 20,020
  • 27
  • 85
  • 160
  • 5
    You cannot build a single binary that runs on both Mac and Linux, if that is what you mean. They use different binary formats, Mach-O and ELF. – Jeremiah Winsley Jun 15 '15 at 13:29

1 Answers1

10

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"
Colin Nicholson
  • 1,331
  • 12
  • 18