- Hands-On GUI Application Development in Go
- Andrew Williams
- 184字
- 2025-04-04 14:54:22
Building for windows on Linux or macOS
Building for Windows from another platform requires an installation of mingw (similar to what we installed on Windows to support CGo). The details for setting up cross-compilation can be found in the Cross compiling for Windows with CGo section of an Appendix, Cross-Compiler Setup.
The main steps are outlined here for quick reference:
Using your package manager (Homebrew on macOS and various on Linux), install the mingw package, which is usually named mingw-w64-clang or w64-mingw. If you cannot find this package, it can be installed directly using the instructions at https://github.com/tpoechtrager/wclang.
Once installed, we need to set up the appropriate build flags—specifically CC=x86_64-w64-mingw32-clang (for the C toolchain) and CXX=x86_64-w64-mingw32-g++ (for C++ requirements). Assuming you also have set CGO_ENABLED=1 and GOOS=windows, you can build the Windows binary. Looking at the resulting hello.exe file, you can see it's an MS Windows binary:

When building from macOS, you can use Homebrew to install the mingw-w64 package.