Building Bitcoin-Rebooted on Native Windows ================================== This document describes the installation of the mysys and mingw tools as well as the build dependencies and then finally the compilation of the bitcoin binaries. If it based on the gracious work posted at https://bitcointalk.org/index.php?topic=149479.0 Unless otherwise specified, all work is done in a msys shell (mingw) NOTE: consider using -j switch with mingw32-make to speed up compilation process. On a quad core -j4 or -j5 should give the best results. On a dual socket xeon with 8 cores per socket and hyper-threading, that would be -j32. NOTE: These instructions will allow you to build Bitcoin-Rebooted as either 32-bit or 64-bit. For the most part, the build instructions are the same after the toolchain and PATH variables are configured. Any differences between the 32-bit and 64-bit build instructions have been noted inline at each instruction step. Also note this guide is a "Step-by-Step" guide, and not a "Click-by-Click" guide. Some experience opening shell windows and the like is expected. Last but hardly least: Getting all the various packages to work together is a bit of an art. If there are little meaningless glitches along the way that you can easily work around by editing a file or two - be happy! Finally: Expect this process to take several hours in setup, and about another to actually compile the qt executable. Prepare your build system ------------------------- 1.1 Install msys shell: http://sourceforge.net/projects/mingw/files/Installer/mingw-get-setup.exe/download From MinGW installation manager -> All packages -> MSYS mark the following for installation: msys-base-bin msys-autoconf-bin msys-automake-bin msys-libtool-bin Make sure no mingw packages are checked for installation or present from a previous install. Only the above msys packages should be installed. Also make sure that msys-gcc and msys-w32api packages are not installed. then click on Installation -> Apply changes 1.2 Install MinGW-builds project toolchain: * Note 8.1.0 causes a problem with libpng, which is fixed in 8.2.0 (use if available), otherwise pull 7.3.0 For 32-bit download: http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/7.3.0/threads-posix/dwarf/i686-4.9.2-release-posix-dwarf-rt_v3-rev1.7z/download and unpack it to C:\ For 64-bit download: http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/7.3.0/threads-posix/seh/x86_64-4.9.2-release-posix-seh-rt_v3-rev1.7z/download and unpack it to C:\ 1.3. Ensure that the desired toolchain's bin folder is set in your PATH environment variable. This will control which toolchain, 32-bit or 64-bit, is used for building. On Windows 7 your path should look something like: For 32-bit builds: C:\mingw32\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\ For 64-bit builds: C:\mingw64\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\ IMPORTANT: It is fine to have both the 32-bit and 64-bit toolchains installed at the same time, however you should only have one in your PATH variable at a time. If you place both in your PATH, then the build will be made with whichever toolchain path that is listed first. NOTE: If you install both toolchains, when you switch between them remember that you need to rebuild all of the dependencies with the same toolchain as you are building the bitcoin client, otherwise linking will fail if you try to mix 32-bit and 64-bit binaries. 1.4 Additional checks: C:\MinGW\bin should contain nothing but mingw-get.exe. Create a shortcut to C:\MinGw\msys\1.0\msys.bat on your desktop. Double-click on the shortcut to start a msys shell. For the 32-bit toolchain your gcc -v output should be: $ gcc -v Using built-in specs. COLLECT_GCC=c:\mingw32\bin\gcc.exe COLLECT_LTO_WRAPPER=c:/mingw32/bin/../libexec/gcc/i686-w64-mingw32/7.3.0/lto-wrapper.exe Target: i686-w64-mingw32 Configured with: ../../../src/gcc-7.3.0/configure --host=i686-w64-mingw32 --build=i686-w64-mingw32 --target=i686-w64-mingw32 --prefix=/mingw32 --with-sysroot=/c/mingw730/i686-492-posix-dwarf-rt_v3-rev1/mingw32 --with-gxx-include-dir=/mingw32/i686-w64-mingw32/include/c++ --enable-shared --enable-static --disable-multilib --enable-languages=ada,c,c++,fortran,objc,obj-c++,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-sjlj-exceptions --with-dwarf2 --disable-isl-version-check --disable-cloog-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=i686 --with-tune=generic --with-libiconv --with-system-zlib --with-gmp=/c/mingw730/prerequisites/i686-w64-mingw32-static --with-mpfr=/c/mingw730/prerequisites/i686-w64-mingw32-static --with-mpc=/c/mingw810/prerequisites/i686-w64-mingw32-static --with-isl=/c/mingw730/prerequisites/i686-w64-mingw32-static --with-cloog=/c/mingw730/prerequisites/i686-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion='i686-posix-dwarf-rev1, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/c/mingw730/i686-810-posix-dwarf-rt_v3-rev1/mingw32/opt/include -I/c/mingw730/prerequisites/i686-zlib-static/include -I/c/mingw730/prerequisites/i686-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/c/mingw730/i686-730-posix-dwarf-rt_v3-rev1/mingw32/opt/include -I/c/mingw730/prerequisites/i686-zlib-static/include -I/c/mingw730/prerequisites/i686-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/c/mingw492/i686-730-posix-dwarf-rt_v3-rev1/mingw32/opt/lib -L/c/mingw730/prerequisites/i686-zlib-static/lib -L/c/mingw730/prerequisites/i686-w64-mingw32-static/lib -Wl,--large-address-aware' Thread model: posix gcc version 7.3.0 (i686-posix-dwarf-rev1, Built by MinGW-W64 project) For the 64-bit toolchain your gcc -v output should be: $ gcc -v Using built-in specs. COLLECT_GCC=C:\mingw64\bin\gcc.exe COLLECT_LTO_WRAPPER=C:/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/7.3.0/lto-wrapper.exe Target: x86_64-w64-mingw32 Configured with: ../../../src/gcc-7.3.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw730/x86_64-492-posix-seh-rt_v3-rev1/mingw64 --with-gxx-include-dir=/mingw64/x86_64-w64-mingw32/include/c++ --enable-shared --enable-static --disable-multilib --enable-languages=ada,c,c++,fortran,objc,obj-c++,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-isl-version-check --disable-cloog-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/mingw730/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw730/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw730/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw730/prerequisites/x86_64-w64-mingw32-static --with-cloog=/c/mingw730/prerequisites/x86_64-w64-mingw32-static --enable-cloog-backend=isl --with-pkgversion='x86_64-posix-seh-rev1, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/c/mingw730/x86_64-810-posix-seh-rt_v3-rev1/mingw64/opt/include -I/c/mingw730/prerequisites/x86_64-zlib-static/include -I/c/mingw730/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/c/mingw730/x86_64-730-posix-seh-rt_v3-rev1/mingw64/opt/include -I/c/mingw730/prerequisites/x86_64-zlib-static/include -I/c/mingw730/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/c/mingw492/x86_64-730-posix-seh-rt_v3-rev1/mingw64/opt/lib -L/c/mingw730/prerequisites/x86_64-zlib-static/lib -L/c/mingw730/prerequisites/x86_64-w64-mingw32-static/lib ' Thread model: posix gcc version 7.3.0 (x86_64-posix-seh-rev1, Built by MinGW-W64 project) 2. Download, unpack and build required dependencies. Save them in c:\deps folder. *** Note: If your PC can handle it, in most cases (check for obvious references on command lines) you can run the package builds below in parallel. 2.1 OpenSSL: http://www.openssl.org/source/openssl-1.0.2o.tar.gz From a MinGw shell (C:\MinGW\msys\1.0\msys.bat), unpack the source archive with tar (this will avoid symlink issues) then configure and make: NOTE: For 32-bit builds, when you run the ./Configure command below, you must change mingw64 to mingw. cd /c/deps/ tar xvfz openssl-1.0.2o.tar.gz cd openssl-1.0.2o ./Configure no-zlib no-shared no-dso no-krb5 no-camellia no-capieng no-cast no-cms no-dtls1 no-gost no-gmp no-heartbeats no-idea no-jpake no-md2 no-mdc2 no-rc5 no-rdrand no-rfc3779 no-rsax no-sctp no-seed no-sha0 no-static_engine no-whirlpool no-rc2 no-rc4 no-ssl2 no-ssl3 mingw64 make depend make -j4 Note: You will probably find it convenient to resize THIS DOCUMENT window to about 1/2 size so that you can run it side-by-side with your Mingw64 shell window - or keep it open on another screen 2.2 Berkeley DB: http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz From a MinGW shell unpack the source archive, configure and make: cd /c/deps/ tar xvfz db-5.3.28.NC.tar.gz cd db-5.3.28.NC/build_unix ../dist/configure --enable-mingw --enable-cxx --disable-shared --disable-replication make -j4 Note: You probably want to copy & paste the configure command above. Copy as you normally world in windows, then paste using the MINGW64 window top-bar option (Edit->paste) 2.3 Boost: http://sourceforge.net/projects/boost/files/boost/1.65.0/ Download either the zip or the 7z archive, unpack boost inside your C:\deps folder, then bootstrap and compile from a Windows command prompt: cd C:\deps\boost_1_65_0\ bootstrap.bat gcc b2 --build-type=complete --with-chrono --with-filesystem --with-program_options --with-system --with-thread toolset=gcc variant=release link=static threading=multi runtime-link=static stage This will compile the required boost libraries and put them into the stage folder (C:\deps\boost_1_65_0\stage). NOTE: make sure you don't use tarballs, as unix EOL markers can break batch files. Note: the b2 steps takes awhile to complete - go grab a beer if you like. 2.3.1 Libevent 2.1.8: http://libevent.org (The sourceforge.net release is out-of-date) Download libevent-2.1.8-stable.tar.gz, then run from the mysys shell: tar xvfz libevent-2.1.8-stable.tar.gz mv ./libevent-2.1.8-stable ./libevent-2.1.8 cd libevent-2.1.8 ./autogen.sh ./configure make -j4 Old source: Libevent 2.0.22: https://sourceforge.net/projects/levent/files/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz/download * Old source notes (just in case your using this guide for some other coin): * Make will likely fail with a: pnglibconf.h:200:54: error: expected identifier or '(' before '-' token * Fix by editing pnglibconf.h and removing the extra tab and spaces on the #defines near the bottom * Hopefully future releases will have this fixed. * Rerun make after editing and it should complete fine 2.4 Miniupnpc is optional and only needs to be installed if your building a public wallet, for private use UPNP is NOT recommeded, some coins don't allow it on public wallets either Miniupnpc: http://miniupnp.free.fr/files/download.php?file=miniupnpc-2.0.20170509.tar.gz Unpack Miniupnpc to C:\deps, rename containing folder from "miniupnpc-2.0.20170509" to "miniupnpc" then from a Windows command prompt: cd C:\deps\miniupnpc set "OLD_CC=%CC%" set "CC=gcc" mingw32-make -f Makefile.mingw init upnpc-static set "CC=%OLD_CC%" NOTE: Miniupnpc version has been updated to 2.0.20170509 due to CVE-2017-8798 In v2.0.20170509 Makefile.mingw changed the CC definition to "CC ?= gcc" which can cause issues, so the value for CC needs to be explicitly set prior to calling mingw32-make. 2.5 protoc and libprotobuf: Download https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz Then from msys shell: tar xvfz protobuf-2.6.1.tar.gz cd /c/deps/protobuf-2.6.1 configure --disable-shared make 2.6 qrencode: Download and unpack http://download.sourceforge.net/libpng/libpng-1.6.34.tar.gz inside your deps folder then configure and make: cd /c/deps/libpng-1.6.34 configure --disable-shared make * Make will likely fail with a: pnglibconf.h:200:54: error: expected identifier or '(' before '-' token * Fix by editing (use wordpad) pnglibconf.h and removing the extra tab and spaces on the #defines near the bottom * Hopefully future releases will have this fixed (1.6.35 does not...). * Rerun make after editing and it should complete fine cp .libs/libpng16.a .libs/libpng.a Download and unpack http://fukuchi.org/works/qrencode/qrencode-4.0.2.tar.gz inside your deps folder then configure and make: NOTE: If you are using the 32-bit toolchain, use the following LIBS line instead: LIBS="../libpng-1.6.34/.libs/libpng.a /c/mingw32/i686-w64-mingw32/lib/libz.a" \ cd /c/deps/qrencode-4.0.2 LIBS="../libpng-1.6.34/.libs/libpng.a /c/mingw64/x86_64-w64-mingw32/lib/libz.a" \ png_CFLAGS="-I../libpng-1.6.34" \ png_LIBS="-L../libpng-1.6.34/.libs" \ configure --enable-static --disable-shared --without-tools make 2.7 Qt 5 libraries: * Note: Personally found this to be the biggest pain to get to compile. This step can take hours as well. Qt must be configured with ssl and zlib support. Download and unpack Qt base and tools sources: http://download.qt-project.org/archive/qt/5.7/5.7.1/submodules/qtbase-opensource-src-5.7.1.7z http://download.qt-project.org/archive/qt/5.7/5.7.1/submodules/qttools-opensource-src-5.7.1.7zr Unpack each into c:\deps\QT and rename the qtbase-opensource-src-5.7.1 to just 5.7.1 /* Optional patch if you get "error 2" when compiling Wordpad edit C:/deps/QT/5.7.1/mkspecs/features/default_post.prf and add the line: static:win32: QMAKE_LFLAGS += $$QMAKE_LFLAGS_STATIC_LIB (Doesn't matter where, but I did it right before the "static:mac:" line) */ End of optional patch Note: This is a really long build. Use -jN where N is the number of threads your PC has. -j4 is just an example. Note: Some report that Windows anti-virus programs need to be disabled (or the ..\QT folder excluded) for QT to be built right Then from a windows command prompt: cd C:\deps\QT\5.7.1 configure.bat -release -opensource -confirm-license -static -make libs -nomake tests -nomake examples -no-sql-sqlite -no-opengl -qt-zlib -qt-pcre -no-icu -no-gif -qt-libpng -qt-libjpeg -no-freetype -qt-zlib -no-angle -openssl -no-dbus -no-audio-backend -no-wmf-backend -no-qml-debug -I c:\deps\openssl-1.0.2o\include -L c:\deps\openssl-1.0.2o mingw32-make -j4 Add C:\deps\Qt\5.7.1\bin;C:\deps\Qt\qttools-opensource-src-5.7.1 to your Windows PATH environment variable (Control Panel -> System -> Advanced System Settings -> Environment Variable) Close and reopen a windows command prompt to pick up the new PATH variable echo %path% - and make sure your additions took cd C:\deps\Qt\qttools-opensource-src-5.7.1 qmake qttools.pro (very fast!) mingw32-make -j4 Note: If anything goes wrong in the above 2 steps, its faster to delete the folders and unpack them again then to do "make clean" type operations. then make a BOOST_ROOT environment variable. best to place it in your mysys.bat file which should be on your desktop now. that way it's there whenever you startup the shell. Enter the following in the mysys shell or add it to the top (after the comment section) of the mysys.bat file. set BOOST_ROOT=/c/deps/boost_1_65_0 Install NSIS: https://sourceforge.net/projects/nsis/files/latest/download !!! Congratulations - you are through all the one-time setup stuff. !!! Now... If you dont already have it, grab git from https://github.com/git-for-windows/git/releases and install it. Launch a git shell window and: git clone https://bitbucket.org/ccgllc/Bitcoin-Rebooted Build Bitcoin-Rebooted ------------- From the mysys shell prompt cd to the root of the source code directory and type the following command (for example, cd c:/Bitcoin-Rebooted and NOT c:/Bitcoin-Rebooted/src): ./autogen.sh Once autogen completes, from the mysys shell prompt enter the following: CPPFLAGS="-I/c/deps/db-4.8.30.NC/build_unix \ -I/c/deps/openssl-1.0.2o/include \ -I/c/deps/libevent-2.1.8/include \ -I/c/deps \ -I/c/deps/protobuf-2.6.1/src \ -I/c/deps/libpng-1.6.34 \ -I/c/deps/qrencode-4.0.2" \ LDFLAGS="-L/c/deps/db-4.8.30.NC/build_unix \ -L/c/deps/openssl-1.0.2o \ -L/c/deps/libevent-2.1.8/.libs \ -L/c/deps/miniupnpc \ -L/c/deps/protobuf-2.6.1/src/.libs \ -L/c/deps/libpng-1.6.34/.libs \ -L/c/deps/QT/5.7.1/lib \ -L/c/deps/qrencode-4.0.2/.libs" \ ./configure \ --disable-upnp-default \ --disable-tests \ --with-qt-incdir=/c/deps/QT/5.7.1/include \ --with-qt-libdir=/c/deps/QT/5.7.1/lib \ --with-qt-plugindir=/c/deps/QT/5.7.1/plugins \ --with-qt-bindir=/c/deps/QT/5.7.1/bin \ --with-protoc-bindir=/c/deps/protobuf-2.6.1/src You can try running the above with "./configure". We have seen ./configure die with errors similar to: ./configure: line 24626: syntax error near unexpected token `fi' ./configure: line 24626: `fi' and ./configure.fixed: line 24741: syntax error near unexpected token `fi' ./configure.fixed: line 24741: `fi' If that occurs, its likely due to a dangling "else". Just edit the configure file and remove or comment out the "else", then save and try again. That seems to fix it. You may need to rince and repeat a few times. We recommend installing an editor like VIM to make it easy to find the right area (in VIM, you just do a :24626 to jump to that line). After the configure script finishes it's finally time to compile. From the msys shell prompt enter the following (this is the same for both 32-bit and 64-bit): make -j4 You can strip the executables if you wish. Stripping will remove debug symbols and greately reduce the final file size of the executables. For example, the v12.1 bitcoin-qt.exe will go from ~241MB to ~26MB. strip src/bit-reboot-tx.exe strip src/bit-reboot-cli.exe strip src/bit-rebootd.exe strip src/qt/bit-reboot-qt.exe Finally, use Windows to create a shortcut and edit with any parameters you wish, like "-datadir=b:\Bit-Reboot". If you want to create a self-installing executable, the easiest way is to use the Windows built in "iexpress.exe". Just run it (Windows key + R) and it will walk your though the process. ... or ... download the open source (e.g. free) innosetup and have a bit more flexibility