Go Cross-Compilation Mac to Linux

From NovaOrdis Knowledge Base
Revision as of 03:17, 9 December 2023 by Ovidiu (talk | contribs) (→‎Overview)
Jump to navigation Jump to search

Internal

Overview

Set GOOS and GOARCH environment variables to appropriate values, during the build.

To build on Mac for Linux:

export GOOS=linux
export GOARCH=amd64


Cgo

https://go.dev/blog/cgo

If Cgo is needed:

brew install FiloSottile/musl-cross/musl-cross
export CC=x86_64-linux-musl-gcc; export CXX=x86_64-linux-musl-g++;  export GOOS=linux; export GOARCH=amd64; export CGO_ENABLED=1; go build [...]