Building for Windows from another platform requires an installation of the mingw
toolchain (similar to that which we installed on Windows to support CGo). This should be available in your package manager with a name similar to mingw-w64-clang
or w64-mingw
, but if not, you can install directly using the instructions at https://github.com/tpoechtrager/wclang.
To install the packages on macOS, it's recommended to use the Homebrew package manager. You probably already have this installed from earlier chapters in this book (for example, when setting up the GTK+ library), but if not, you can download it from https://brew.sh. Once Homebrew is set up, the compiler package is installed using brew install mingw-w64
.
Once installed, the compiler can be used with CGo by setting CC=x86_64-w64-mingw32-gcc
(for the C toolchain) and CXX=x86_64-w64-mingw32-g++
(for C++ requirements).
Installing on Linux should just require finding the correct package in your distribution's listing. For example, for Debian or Ubuntu, you would execute sudo apt-get install gcc-mingw-w64
.
Once installed, the compiler can be used with CGo by setting CC=x86_64-w64-mingw32-gcc
(for the C toolchain) and CXX=x86_64-w64-mingw32-g++
(for C++ requirements).