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;
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 extended
🏏 There are some custom names at play here
You should note that Zig uses the term
amd64 rather than
While the list of supported targets is very long, here are some most common combinations:
As you can tell, the format followed is