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 AppendixCross-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:

Using mingw (x86_64-w64-mingw32-clang), we built a Windows-native UI application on Linux

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

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.68.18