When trying to cross-compile applications for different operating systems and architectures, you can often hit some niche configurations that are difficult to accomodate.
Thankfully Zig can help to alleviate this pain point as it bundles standard libraries for all major platforms ie; GNU libc, musl libc and so on.
Assuming you have Zig already installed, you can cross compile a Go application like so:
$ CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC="zig cc -target x86_64-linux" CXX="zig c++ -target x86_64-linux" go build --tags extendedInfo
You should note that Zig uses the term
amd64rather thanx86_64.
While the list of supported targets is very long, here are some most common combinations:
x86_64-linux-gnux86_64-windows-gnux86_64-macos-muslaarch64-macos-gnu
As you can tell, the format followed is <arch>-<os>-<libc>