Skip to content

Commit e0fc4a7

Browse files
committed
Updated Windows build doc for WSL/Xenial workarounds.
1 parent 6ab0e4c commit e0fc4a7

File tree

1 file changed

+53
-17
lines changed

1 file changed

+53
-17
lines changed

doc/build-windows.md

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ WINDOWS BUILD NOTES
44
Below are some notes on how to build Bitcoin Core for Windows.
55

66
Most developers use cross-compilation from Ubuntu to build executables for
7-
Windows. Cross-compilation is also used to build the release binaries.
7+
Windows. This is also used to build the release binaries.
88

9-
Currently only building on Ubuntu Trusty 14.04 or Ubuntu Zesty 17.04 or later is supported.
10-
Building on Ubuntu Xenial 16.04 is known to be broken, see extensive discussion in issue [8732](https://github.com/bitcoin/bitcoin/issues/8732).
11-
While it may be possible to do so with work arounds, it's potentially dangerous and not recommended.
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.
1215

1316
While there are potentially a number of ways to build on Windows (for example using msys / mingw-w64),
1417
using the Windows Subsystem For Linux is the most straightforward. If you are building with
@@ -19,7 +22,7 @@ Compiling with Windows Subsystem For Linux
1922
-------------------------------------------
2023

2124
With Windows 10, Microsoft has released a new feature named the [Windows
22-
Subsystem for Linux](https://msdn.microsoft.com/commandline/wsl/about). This
25+
Subsystem for Linux (WSL)](https://msdn.microsoft.com/commandline/wsl/about). This
2326
feature allows you to run a bash shell directly on Windows in an Ubuntu-based
2427
environment. Within this environment you can cross compile for Windows without
2528
the need for a separate Linux VM or server.
@@ -57,28 +60,40 @@ installing the toolchain will be different.
5760

5861
First, install the general dependencies:
5962

60-
sudo apt-get install build-essential libtool autotools-dev automake pkg-config bsdmainutils curl
63+
sudo apt install build-essential libtool autotools-dev automake pkg-config bsdmainutils curl git
6164

6265
A host toolchain (`build-essential`) is necessary because some dependency
6366
packages (such as `protobuf`) need to build host utilities that are used in the
6467
build process.
6568

6669
See also: [dependencies.md](dependencies.md).
6770

68-
If you're building on Ubuntu 17.04 or later, run these two commands, selecting the 'posix' variant for both,
69-
to work around issues with mingw-w64. See issue [8732](https://github.com/bitcoin/bitcoin/issues/8732) for more information.
70-
```
71-
sudo update-alternatives --config x86_64-w64-mingw32-g++
72-
sudo update-alternatives --config x86_64-w64-mingw32-gcc
73-
```
74-
7571
## Building for 64-bit Windows
7672

77-
To build executables for Windows 64-bit, install the following dependencies:
73+
The first step is to install the mingw-w64 cross-compilation tool chain. Due to different Ubuntu
74+
packages for each distribution and problems with the Xenial packages the steps for each are different.
7875

79-
sudo apt-get install g++-mingw-w64-x86-64 mingw-w64-x86-64-dev
76+
Common steps to install mingw32 cross compiler tool chain:
8077

81-
Then build using:
78+
sudo apt install g++-mingw-w64-x86-64
79+
80+
Ubuntu Trusty 14.04:
81+
82+
No further steps required
83+
84+
Ubuntu Xenial 16.04 and Windows Subsystem for Linux <sup>[1](#footnote1),[2](#footnote2)</sup>:
85+
86+
sudo apt install software-properties-common
87+
sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu zesty universe"
88+
sudo apt update
89+
sudo apt upgrade
90+
sudo update-alternatives --config x86_64-w64-mingw32-g++ # Set the default mingw32 g++ compiler option to posix.
91+
92+
Ubuntu Zesty 17.04 <sup>[2](#footnote2)</sup>:
93+
94+
sudo update-alternatives --config x86_64-w64-mingw32-g++ # Set the default mingw32 g++ compiler option to posix.
95+
96+
Once the tool chain is installed the build steps are common:
8297

8398
PATH=$(echo "$PATH" | sed -e 's/:\/mnt.*//g') # strip out problematic Windows %PATH% imported var
8499
cd depends
@@ -92,7 +107,11 @@ Then build using:
92107

93108
To build executables for Windows 32-bit, install the following dependencies:
94109

95-
sudo apt-get install g++-mingw-w64-i686 mingw-w64-i686-dev
110+
sudo apt install g++-mingw-w64-i686 mingw-w64-i686-dev
111+
112+
For Ubuntu Xenial 16.04, Ubuntu Zesty 17.04 and Windows Subsystem for Linux <sup>[2](#footnote2)</sup>:
113+
114+
sudo update-alternatives --config i686-w64-mingw32-g++ # Set the default mingw32 g++ compiler option to posix.
96115

97116
Then build using:
98117

@@ -117,3 +136,20 @@ as they appear in the release `.zip` archive. This can be done in the following
117136
way. This will install to `c:\workspace\bitcoin`, for example:
118137

119138
make install DESTDIR=/mnt/c/workspace/bitcoin
139+
140+
Footnotes
141+
---------
142+
143+
<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
144+
causes two of the bitcoin executables to crash shortly after start up. The bug is related to the
145+
-fstack-protector-all g++ compiler flag which is used to mitigate buffer overflows.
146+
Installing the mingw-w64 packages from the Ubuntu 17 distribution solves the issue, however, this is not
147+
an officially supported approach and it's only recommended if you are prepared to reinstall WSL/Ubutntu should
148+
something break.
149+
150+
<a name="footnote2">2</a>: Starting from Ubuntu Xenial 16.04 both the 32 and 64 bit mingw-w64 packages install two different
151+
compiler options to allow a choice between either posix or win32 threads. The default option is win32 threads which is the more
152+
efficient since it will result in binary code that links directly with the Windows kernel32.lib. Unfortunately, the headers
153+
required to support win32 threads conflict with some of the classes in the C++11 standard library in particular std::mutex.
154+
It's not possible to build the bitcoin code using the win32 version of the mingw-w64 cross compilers (at least not without
155+
modifying headers in the bitcoin source code).

0 commit comments

Comments
 (0)