Merge #11676: contrib/init: Update openrc-run filename
[bitcoinplatinum.git] / doc / build-windows.md
blobc415595e439561aaab7ca48dea059232715d2890
1 WINDOWS BUILD NOTES
2 ====================
4 Below are some notes on how to build Bitcoin Core for Windows.
6 Most developers use cross-compilation from Ubuntu to build executables for
7 Windows. This is also used to build the release binaries.
9 Building on Ubuntu Trusty 14.04 is recommended.
10 At the time of writing the Windows Subsystem for Linux installs Ubuntu Xenial 16.04. The default cross
11 compiler package for Ubuntu Xenial does not produce working executables for some of the bitcoin applications.
12 It is possible to build on Ubuntu Xenial by installing the cross compiler packages from
13 Ubuntu Zesty, see the steps below.
14 Building on Ubuntu Zesty 17.04 up to 17.10 has been verified to work.
16 While there are potentially a number of ways to build on Windows (for example using msys / mingw-w64),
17 using the Windows Subsystem For Linux is the most straightforward. If you are building with
18 another method, please contribute the instructions here for others who are running versions
19 of Windows that are not compatible with the Windows Subsystem for Linux.
21 Compiling with Windows Subsystem For Linux
22 -------------------------------------------
24 With Windows 10, Microsoft has released a new feature named the [Windows
25 Subsystem for Linux (WSL)](https://msdn.microsoft.com/commandline/wsl/about). This
26 feature allows you to run a bash shell directly on Windows in an Ubuntu-based
27 environment. Within this environment you can cross compile for Windows without
28 the need for a separate Linux VM or server.
30 This feature is not supported in versions of Windows prior to Windows 10 or on
31 Windows Server SKUs. In addition, it is available [only for 64-bit versions of
32 Windows](https://msdn.microsoft.com/en-us/commandline/wsl/install_guide).
34 For Windows 10 systems with the Fall Creators Update applied (version >= 16215.0) use the Windows Store
35 to install Ubuntu. Search for "Linux" in the Windows Store and install the free "Ubuntu" application.
36 Full instructions are available on the above link.
38 To get the bash shell, you must first activate the feature in Windows.
40 1. Turn on Developer Mode
41   * Open Settings -> Update and Security -> For developers
42   * Select the Developer Mode radio button
43   * Restart if necessary
44 2. Enable the Windows Subsystem for Linux feature
45   * From Start, search for "Turn Windows features on or off" (type 'turn')
46   * Select Windows Subsystem for Linux (beta)
47   * Click OK
48   * Restart if necessary
49 3. Complete Installation
50   * Open a cmd prompt and type "bash"
51   * Accept the license
52   * Create a new UNIX user account (this is a separate account from your Windows account)
54 After the bash shell is active, you can follow the instructions below, starting
55 with the "Cross-compilation" section. Compiling the 64-bit version is
56 recommended but it is possible to compile the 32-bit version.
58 Cross-compilation
59 -------------------
61 These steps can be performed on, for example, an Ubuntu VM. The depends system
62 will also work on other Linux distributions, however the commands for
63 installing the toolchain will be different.
65 First, install the general dependencies:
67     sudo apt install build-essential libtool autotools-dev automake pkg-config bsdmainutils curl git
69 A host toolchain (`build-essential`) is necessary because some dependency
70 packages (such as `protobuf`) need to build host utilities that are used in the
71 build process.
73 See also: [dependencies.md](dependencies.md).
75 ## Building for 64-bit Windows
77 The first step is to install the mingw-w64 cross-compilation tool chain. Due to different Ubuntu
78 packages for each distribution and problems with the Xenial packages the steps for each are different.
80 Common steps to install mingw32 cross compiler tool chain:
82     sudo apt install g++-mingw-w64-x86-64
84 Ubuntu Trusty 14.04:
86     No further steps required
88 Ubuntu Xenial 16.04 and Windows Subsystem for Linux <sup>[1](#footnote1),[2](#footnote2)</sup>:
90     sudo apt install software-properties-common
91     sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu zesty universe"
92     sudo apt update
93     sudo apt upgrade
94     sudo update-alternatives --config x86_64-w64-mingw32-g++ # Set the default mingw32 g++ compiler option to posix.
96 Ubuntu Zesty 17.04 <sup>[2](#footnote2)</sup>:
98     sudo update-alternatives --config x86_64-w64-mingw32-g++ # Set the default mingw32 g++ compiler option to posix.
100 Once the tool chain is installed the build steps are common:
102     PATH=$(echo "$PATH" | sed -e 's/:\/mnt.*//g') # strip out problematic Windows %PATH% imported var
103     cd depends
104     make HOST=x86_64-w64-mingw32
105     cd ..
106     ./autogen.sh # not required when building from tarball
107     CONFIG_SITE=$PWD/depends/x86_64-w64-mingw32/share/config.site ./configure --prefix=/
108     make
110 ## Building for 32-bit Windows
112 To build executables for Windows 32-bit, install the following dependencies:
114     sudo apt install g++-mingw-w64-i686 mingw-w64-i686-dev
116 For Ubuntu Xenial 16.04, Ubuntu Zesty 17.04 and Windows Subsystem for Linux <sup>[2](#footnote2)</sup>:
118     sudo update-alternatives --config i686-w64-mingw32-g++  # Set the default mingw32 g++ compiler option to posix.
120 Then build using:
122     PATH=$(echo "$PATH" | sed -e 's/:\/mnt.*//g') # strip out problematic Windows %PATH% imported var
123     cd depends
124     make HOST=i686-w64-mingw32
125     cd ..
126     ./autogen.sh # not required when building from tarball
127     CONFIG_SITE=$PWD/depends/i686-w64-mingw32/share/config.site ./configure --prefix=/
128     make
130 ## Depends system
132 For further documentation on the depends system see [README.md](../depends/README.md) in the depends directory.
134 Installation
135 -------------
137 After building using the Windows subsystem it can be useful to copy the compiled
138 executables to a directory on the windows drive in the same directory structure
139 as they appear in the release `.zip` archive. This can be done in the following
140 way. This will install to `c:\workspace\bitcoin`, for example:
142     make install DESTDIR=/mnt/c/workspace/bitcoin
144 Footnotes
145 ---------
147 <a name="footnote1">1</a>: There is currently a bug in the 64 bit mingw-w64 cross compiler packaged for WSL/Ubuntu Xenial 16.04 that
148 causes two of the bitcoin executables to crash shortly after start up. The bug is related to the
149 -fstack-protector-all g++ compiler flag which is used to mitigate buffer overflows.
150 Installing the mingw-w64 packages from the Ubuntu 17 distribution solves the issue, however, this is not
151 an officially supported approach and it's only recommended if you are prepared to reinstall WSL/Ubutntu should
152 something break.
154 <a name="footnote2">2</a>: Starting from Ubuntu Xenial 16.04 both the 32 and 64 bit mingw-w64 packages install two different
155 compiler options to allow a choice between either posix or win32 threads. The default option is win32 threads which is the more
156 efficient since it will result in binary code that links directly with the Windows kernel32.lib. Unfortunately, the headers
157 required to support win32 threads conflict with some of the classes in the C++11 standard library in particular std::mutex.
158 It's not possible to build the bitcoin code using the win32 version of the mingw-w64 cross compilers (at least not without
159 modifying headers in the bitcoin source code).