- Hands-On GUI Application Development in Go
- Andrew Williams
- 110字
- 2025-04-04 14:54:22
macOS
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:
- brew install gtk+3
- export HOMEBREW_BUILD_FROM_SOURCE=1
- brew install FiloSottile/musl-cross/musl-cross
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:

Building a Linux executable from macOS