The current Monero source code will build cleanly on Win32 without any further patching, but the build environment still needs customization. Since the Win64 build uses MSYS2, we will also use MSYS2 for this build (but you could also have used MSYS1 instead).

MSYS2 ships with multi-lib compilers by default - that means that whether you're on 32 bit or 64 bit Windows, the same toolchain can be used to build both 32 and 64 bit binaries. Unfortunately, the 32 bit support there is broken, so you will still need to install a different toolchain for 32 bit builds. The one that works is here https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/4.9.3/threads-win32/sjlj/i686-4.9.3-release-win32-sjlj-rt_v4-rev1.7z/download

Explanation: MSYS2's default g++ compiler uses POSIX-style threads, using their own emulation library. It also uses DWARF-based exception handlers on Win32, which only work in pure g++-compiled code. In particular, DWARF-based exception handling doesn't work when mixed with Windows runtime code and will crash. The toolchain linked above uses native Win32 threads, and setjmp/longjmp exception handlers. The native Win32 thread support is more stable, and the setjmp/longjmp exception handlers work in mixed Windows/Gnu code without any problem. (The setjmp/longjmp approach is always more portable but can be slower than other mechanisms. It's not an issue in Monero because exceptions aren't used with high frequency.) Note that I have explicitly chosen the gcc-4.9.3 package above; the latest available is gcc-5.3.0 but that will not work. Stick with 4.9.3; the 5.3.0 optimizer has bugs that will just cause the resulting binaries to crash.

MSYS2 ships with a lot of libraries ready-made. The plain C libraries can be used without trouble, but C++ libraries like libboost must be compiled using the same toolchain, due to the thread model and exception handling model. So for Monero you will need to compile libboost yourself.

You'll need 2GB RAM to generate the Release build. You'll need 3GB RAM for a Debug build, and you'll have to set the LARGEADDRESSAWARE flag on the cc1plus.exe binary to make it work.

Dependencies: mingw-w64, MSYS2, cmake, make, Boost 1.60.

Preparing the Build Environment

I am downloading files to /z just for example. (That's Z:\ for Windows paths.) Use whatever path is appropriate on your own system.

Download the MSYS2 installer, 64-bit or 32-bit as needed, and run it.

Use the shortcut associated with your architecture to launch the MSYS2 environment. For building Win32 binaries use the MinGW-w64 Win32 Shell shortcut.

Update the packages in your MSYS2 install:

pacman -Sy pacman -Su --ignoregroup base pacman -Su

You will have to exit the shell and start a new one after pacman updates itself.

Install dependencies: pacman -S make mingw-w64-i686-cmake p7zip

cmake includes 27 dependencies, some of which will clash with the build toolchain. So after it installs, we move it aside.

mv /mingw32 /mingw32.1

Download the toolchain and extract it over the MSYS2 path "/mingw32". Also grab the OpenSSL installation from the cmake install.

cd /; 7z x /z/i686-4.9.3-release-win32-sjlj-rt_v4-rev1.7z mv mingw32.1/include/openssl mingw32/include mv mingw32.1/lib/lib{crypto,ssl}.a mingw32/lib

Download the Boost 1.60 source and extract it.

cd /z; 7z x boost_1_60_0.7z

Prepare the Boost build tools - we're going to use a Windows cmd shell for this. Use the Start -> Run menu, enter "cmd"

Z: cd boost_1_60_0\tools\build\src\engine path C:\msys32\mingw32\bin;%PATH% .\build.bat gcc ... copy bin.ntx86\*.exe ..\..\..\..

Go back to the MSYS2 shell

cd /z/boost_1_60_0 cat < project-config.jam import option ; using gcc ; option.set keep-going : false ; EOF

Compile and install Boost

./b2 --layout=tagged --build-type=minimal --prefix=/mingw32/boost runtime-link=static install define=BOOST_USE_WINAPI_VERSION=0x0501 --with-chrono --with-date_time --with-filesystem --with-program_options --with-regex --with-serialization --with-system --with-thread --with-test --with-locale

Build Monero

cd bitmonero mkdir -p build/release cd build/release /mingw32.1/bin/cmake -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release -DARCH=i686 -DCMAKE_TOOLCHAIN_FILE=../../cmake/32-bit-toolchain.cmake -DMSYS2_FOLDER=c:/msys32 ../.. make