February 2019
Intermediate to advanced
450 pages
11h 59m
English
To cross-compile with macOS, we need to install a package manager. The easiest and most complete is Homebrew—you can install it from https://brew.sh/. The recommended toolchain for Linux compilation is musl-cross, which is in the FiloSottile/musl-cross/musl-cross package. With Homebrew installed, execute the following commands in your Terminal window:
Once that is completed, you should be able to build for Linux by setting the GOOS=linux, GOARCH=amd64, CGO_ENABLED=1, and CC=x86_64-linux-musl-gcc environment variables with CXX=x86_64-linux-musl-g++. You can then build as normal, resulting in a Linux executable instead of macOS:
Read now
Unlock full access