Skip to content

Windows Build Notes MinGW on Windows 10

spacecrypto edited this page Jul 23, 2019 · 2 revisions

NOTE: We never got these instructions to work, and they are now superceded with our Ubuntu 16-based Windows Build Procedure.

Build Marscoin's Windows stack using the MinGW approach

1. Set up MinGW

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

IMPORTANT: 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 the msys-gcc and msys-w32api packages are not installed. This will cause compiler errors later if these older versions are 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.  

Eg: Add c:\mingw64\bin to PATH.

2. Dependencies

Download, unpack and build required dependencies. Save them in c:\deps folder.

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.

Exact Steps:

$ cd /c/deps/

$ tar xvfz openssl-1.0.2s.tar.gz

$ cd openssl-1.0.2s

$ ./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

From a MinGW shell unpack the source archive, configure and make:

$ cd /c/deps/

$ tar xvfz db-4.8.30.tar.gz

$ cd db-4.8.30/build_unix

$ ../dist/configure --enable-mingw --enable-cxx --disable-shared --disable-replication

$ make

Download either the zip or the 7z archive, unpack boost inside your C:\deps folder, then bootstrap and compile from a Windows command prompt:

NOTE: make sure you don't use tarballs, as unix EOL markers can break batch files.

This will compile the required boost libraries and put them into the stage folder (C:\deps\boost_1_59_0\stage).

NOTE: Run these commands with the normal CMD interpreter, not msys!!

C:\deps\boost_1_59_0> cd C:\deps\boost_1_59_0\

C:\deps\boost_1_59_0> ./bootstrap.bat gcc

C:\deps\boost_1_59_0> ./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

Download and unpack, then run from the mysys shell:

$ tar xvfz libevent-2.0.22-stable.tar.gz 

$ mv ./libevent-2.0.22-stable ./libevent-2.0.22

$ cd libevent-2.0.22

$ ./configure --disable-shared

$ make

Note: Miniupnpc is optional and only needs to be installed if your building a public wallet, for private use UPNP is NOT recommended.

Unpack Miniupnpc to C:\deps, rename containing folder from "miniupnpc-2.0.20170509" to "miniupnpc" then from a Windows command prompt:

C:\> cd C:\deps\miniupnpc

C:\deps\miniupnpc> set "OLD_CC=%CC%"

C:\deps\miniupnpc> set "CC=gcc"

C:\deps\miniupnpc> mingw32-make -f Makefile.mingw init upnpc-static

C:\deps\miniupnpc> 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.

Then from msys shell:

$ tar xvfz protobuf-2.6.1.tar.gz

$ cd /c/deps/protobuf-2.6.1

$ configure --disable-shared

$ make

Download and unpack inside your deps folder then configure and make:

$ tar xvzf libpng-1.6.37.tar.gz

$ cd libpng-1.6.37

$ configure --disable-shared

NOTE: There is an error in pnglibconf.h where several #define statements have extra tabs & spaces before the value set. Open this file up in a text editor and fix these before running make.

$ make

$ cp .libs/libpng16.a .libs/libpng.a

Download and unpack 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" \

$ tar xvzf qrencode-4.0.2.tar.gz

$ cd 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.9 Qt5

Download Qt5 base and tools: 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.7z

Unpack each into the new subfolder C:\deps\QT and rename the qtbase-opensource-src-5.7.1 to just 5.7.1

So when done you should have these two directories:

C:\deps\QT\5.7.1

C:\deps\QT\qttools-opensource-src-5.7.1

NOTE: Some report that Windows anti-virus programs need to be disabled (or the ..\QT folder excluded) for QT to be built right

NOTE: Qt must be configured with ssl and zlib support.

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: If anything goes wrong with QT compilation, its faster to delete the folders and unpack them again then to do "make clean" type operations.

To prevent an error during Marscoin configure when QT static plugins are not found: Edit the file 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)

Next, run these steps from a windows command prompt:

C:\> cd C:\deps\QT\5.7.1

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.2s\include -L c:\deps\openssl-1.0.2s

C:\deps\QT\5.7.1> mingw32-make -j4

Add to $PATH: C:\deps\Qt\5.7.1\bin;C:\deps\Qt\qttools-opensource-src-5.7.1 (Control Panel -> System -> Advanced System Settings -> Environment Variable)

Close and reopen a windows command prompt to pick up the new PATH variable

Confirm your PATH is correct:

C:\> echo %path%

Run the following commands

C:\> cd C:\deps\Qt\qttools-opensource-src-5.7.1

C:\deps\Qt\qttools-opensource-src-5.7.1> qmake qttools.pro

C:\deps\Qt\qttools-opensource-src-5.7.1> mingw32-make -j4

3 Compiling Marscoin

3.1 Set up environment variables

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_59_0

3.2 Run Autogen.sh

From the mysys shell prompt cd to the root of the source code directory and type the following command (for example, cd c:/marscoin and NOT c:/marscoin/src):

$ ./autogen.sh

3.3 Set Build Flags & Configure

Once autogen completes, from the mysys shell prompt enter the following:

$ CPPFLAGS="-I/c/deps/db-4.8.30/build_unix \
-I/c/deps/openssl-1.0.2s/include \
-I/c/deps/libevent-2.0.22/include \
-I/c/deps \
-I/c/deps/protobuf-2.6.1/src \
-I/c/deps/libpng-1.6.37 \
-I/c/deps/qrencode-4.0.2" \
LDFLAGS="-L/c/deps/db-4.8.30/build_unix \
-L/c/deps/openssl-1.0.2s \
-L/c/deps/libevent-2.0.22/.libs \
-L/c/deps/protobuf-2.6.1/src/.libs \
-L/c/deps/libpng-1.6.37/.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 \
--with-incompatible-bdb

NOTE: If using miniupnpc, add the following line to LDFLAGS:

-L/c/deps/miniupnpc \

3.4 Make

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

3.5 Strip

Finally you can strip the executables if you wish. Stripping will remove debug symbols and greatly reduce the final file size of the executables.

strip src/marscoin-tx.exe strip src/marscoin-cli.exe strip src/marscoind.exe strip src/qt/marscoin-qt.exe

Clone this wiki locally