Please login or register.

Building Monero v0.9.2 on Win32

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
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
  • The build process will also copy the OpenSSL libraries and winpthread DLL to your bin directory. These are just remnants of the old build process and aren't needed to run the binaries.
Replies: 1
Arux edited 8 years ago Weight: 0 | Link [ - ]

many thanks to you, hyc, for sharing your precious knowledges.

i built my own win32 binaries by following the guidance and all was fine.

for some reason, my msys2 default path is c:/msys64 instead of c:/msys32, not hard to adjust.

i was able to launch successfully the binaries on win7 x86 [edit] and i can confirm correct synchronization of the whole blockchain from scratch on my VM

Creating the logger system
2016-Mar-21 19:55:05.886563 Initializing cryptonote protocol...
2016-Mar-21 19:55:05.886563 Cryptonote protocol initialized OK
2016-Mar-21 19:55:05.886563 Initializing p2p server...
2016-Mar-21 19:55:07.324063 Set limit-up to 2048 kB/s
2016-Mar-21 19:55:07.324063 Set limit-down to 8192 kB/s
2016-Mar-21 19:55:07.324063 Set limit-up to 2048 kB/s
2016-Mar-21 19:55:07.324063 Set limit-down to 8192 kB/s
2016-Mar-21 19:55:07.324063 Binding on 0.0.0.0:18080
2016-Mar-21 19:55:07.324063 Net service bound to 0.0.0.0:18080
2016-Mar-21 19:55:07.324063 Attempting to add IGD port mapping.
2016-Mar-21 19:55:08.355313 Added IGD port mapping.
2016-Mar-21 19:55:08.355313 P2p server initialized OK
2016-Mar-21 19:55:08.355313 Initializing core rpc server...
2016-Mar-21 19:55:08.355313 Binding on 127.0.0.1:18081
2016-Mar-21 19:55:08.355313 Core rpc server initialized OK on port: 18081
2016-Mar-21 19:55:08.355313 Initializing core...
2016-Mar-21 19:55:08.370938 Loading blockchain from folder C:\ProgramData\bitmonero\lmdb ...
2016-Mar-21 19:55:08.370938 option: fastest
2016-Mar-21 19:55:08.370938 option: async
2016-Mar-21 19:55:08.370938 option: 1000
2016-Mar-21 19:55:09.120938 Blockchain initialized. last block: 1007252, d0.h0.m6.s54 time ago, current difficulty: 1038900882
[1458586530] libunbound[1836:0] error: serviced_tcp_initiate: failed to send tcp query
[1458586551] libunbound[1836:0] error: serviced_tcp_initiate: failed to send tcp query
[1458586573] libunbound[1836:0] error: serviced_tcp_initiate: failed to send tcp query
2016-Mar-21 19:56:13.402188 Core initialized OK
2016-Mar-21 19:56:13.402188 Starting core rpc server...
2016-Mar-21 19:56:13.402188 Run net_service loop( 2 threads)...
2016-Mar-21 19:56:13.402188 [SRV_MAIN]Core rpc server started ok
2016-Mar-21 19:56:13.402188 [SRV_MAIN]Starting p2p net loop...
2016-Mar-21 19:56:13.402188 [SRV_MAIN]Run net_service loop( 10 threads)...
2016-Mar-21 19:56:14.402188 [P2P7]
**********************************************************************
The daemon will start synchronizing with the network. It may take up to several
hours.

You can set the level of process detailization* through "set_log " comman
d*, where  is between 0 (no details) and 4 (very verbose).

Use "help" command to see the list of available commands.

Note: in case you need to interrupt the process, use "exit" command. Otherwise,
the current progress won't be saved.
**********************************************************************
2016-Mar-21 19:56:14.402188 [P2P7]
**********************************************************************
Last scheduled hard fork time shows a daemon update is needed now.
**********************************************************************

2016-Mar-21 19:56:15.355313 [P2P9][93.177.184.22:18080 OUT]Sync data returned un
known top block: 1007253 -> 1007254 [1 blocks (0 days) behind]
SYNCHRONIZATION started
2016-Mar-21 19:56:15.870938 [P2P9][199.204.186.187:18080 OUT]Sync data returned
unknown top block: 1007253 -> 1007254 [1 blocks (0 days) behind]
SYNCHRONIZATION started
2016-Mar-21 19:56:16.324063 [P2P7][107.170.19.65:18080 OUT]Sync data returned un
known top block: 1007253 -> 1007254 [1 blocks (0 days) behind]
SYNCHRONIZATION started
2016-Mar-21 19:56:16.511563 [P2P9][79.66.5.47:18080 OUT]Sync data returned unkno
wn top block: 1007253 -> 1007254 [1 blocks (0 days) behind]
SYNCHRONIZATION started
2016-Mar-21 19:56:16.777188 [P2P9][93.177.184.22:18080 OUT]Synced 1007254/100725
4
2016-Mar-21 19:56:16.777188 [P2P7]
**********************************************************************
You are now synchronized with the network. You may now start simplewallet.

Please note, that the blockchain will be saved only after you quit the daemon wi
th "exit" command or if you use "save" command.
Otherwise, you will possibly need to synchronize the blockchain again.

Use "help" command to see the list of available commands.
**********************************************************************
2016-Mar-21 19:56:16.777188 [P2P9][93.177.184.22:18080 OUT] SYNCHRONIZED OK
2016-Mar-21 19:56:16.933438 [P2P7][79.66.5.47:18080 OUT] SYNCHRONIZED OK
2016-Mar-21 19:56:17.027188 [P2P7][107.170.19.65:18080 OUT] SYNCHRONIZED OK
2016-Mar-21 19:56:17.355313 [P2P9][199.204.186.187:18080 OUT] SYNCHRONIZED OK