Merge #12062: Increment MIT Licence copyright header year on files modified in 2017
[bitcoinplatinum.git] / doc / build-unix.md
blobaf567cadeb648efcf5ee663a0674a917e6de70a6
1 UNIX BUILD NOTES
2 ====================
3 Some notes on how to build Bitcoin Core in Unix.
5 (for OpenBSD specific instructions, see [build-openbsd.md](build-openbsd.md))
7 Note
8 ---------------------
9 Always use absolute paths to configure and compile bitcoin and the dependencies,
10 for example, when specifying the path of the dependency:
12         ../dist/configure --enable-cxx --disable-shared --with-pic --prefix=$BDB_PREFIX
14 Here BDB_PREFIX must be an absolute path - it is defined using $(pwd) which ensures
15 the usage of the absolute path.
17 To Build
18 ---------------------
20 ```bash
21 ./autogen.sh
22 ./configure
23 make
24 make install # optional
25 ```
27 This will build bitcoin-qt as well if the dependencies are met.
29 Dependencies
30 ---------------------
32 These dependencies are required:
34  Library     | Purpose          | Description
35  ------------|------------------|----------------------
36  libssl      | Crypto           | Random Number Generation, Elliptic Curve Cryptography
37  libboost    | Utility          | Library for threading, data structures, etc
38  libevent    | Networking       | OS independent asynchronous networking
40 Optional dependencies:
42  Library     | Purpose          | Description
43  ------------|------------------|----------------------
44  miniupnpc   | UPnP Support     | Firewall-jumping support
45  libdb4.8    | Berkeley DB      | Wallet storage (only needed when wallet enabled)
46  qt          | GUI              | GUI toolkit (only needed when GUI enabled)
47  protobuf    | Payments in GUI  | Data interchange format used for payment protocol (only needed when GUI enabled)
48  libqrencode | QR codes in GUI  | Optional for generating QR codes (only needed when GUI enabled)
49  univalue    | Utility          | JSON parsing and encoding (bundled version will be used unless --with-system-univalue passed to configure)
50  libzmq3     | ZMQ notification | Optional, allows generating ZMQ notifications (requires ZMQ version >= 4.x)
52 For the versions used, see [dependencies.md](dependencies.md)
54 Memory Requirements
55 --------------------
57 C++ compilers are memory-hungry. It is recommended to have at least 1.5 GB of
58 memory available when compiling Bitcoin Core. On systems with less, gcc can be
59 tuned to conserve memory with additional CXXFLAGS:
62     ./configure CXXFLAGS="--param ggc-min-expand=1 --param ggc-min-heapsize=32768"
64 Dependency Build Instructions: Ubuntu & Debian
65 ----------------------------------------------
66 Build requirements:
68     sudo apt-get install build-essential libtool autotools-dev automake pkg-config libssl-dev libevent-dev bsdmainutils python3
70 Options when installing required Boost library files:
72 1. On at least Ubuntu 14.04+ and Debian 7+ there are generic names for the
73 individual boost development packages, so the following can be used to only
74 install necessary parts of boost:
76         sudo apt-get install libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-program-options-dev libboost-test-dev libboost-thread-dev
78 2. If that doesn't work, you can install all boost development packages with:
80         sudo apt-get install libboost-all-dev
82 BerkeleyDB is required for the wallet.
84 **For Ubuntu only:** db4.8 packages are available [here](https://launchpad.net/~bitcoin/+archive/bitcoin).
85 You can add the repository and install using the following commands:
87     sudo apt-get install software-properties-common
88     sudo add-apt-repository ppa:bitcoin/bitcoin
89     sudo apt-get update
90     sudo apt-get install libdb4.8-dev libdb4.8++-dev
92 Ubuntu and Debian have their own libdb-dev and libdb++-dev packages, but these will install
93 BerkeleyDB 5.1 or later, which break binary wallet compatibility with the distributed executables which
94 are based on BerkeleyDB 4.8. If you do not care about wallet compatibility,
95 pass `--with-incompatible-bdb` to configure.
97 See the section "Disable-wallet mode" to build Bitcoin Core without wallet.
99 Optional (see --with-miniupnpc and --enable-upnp-default):
101     sudo apt-get install libminiupnpc-dev
103 ZMQ dependencies (provides ZMQ API 4.x):
105     sudo apt-get install libzmq3-dev
107 Dependencies for the GUI: Ubuntu & Debian
108 -----------------------------------------
110 If you want to build Bitcoin-Qt, make sure that the required packages for Qt development
111 are installed. Either Qt 5 or Qt 4 are necessary to build the GUI.
112 If both Qt 4 and Qt 5 are installed, Qt 5 will be used. Pass `--with-gui=qt4` to configure to choose Qt4.
113 To build without GUI pass `--without-gui`.
115 To build with Qt 5 (recommended) you need the following:
117     sudo apt-get install libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools libprotobuf-dev protobuf-compiler
119 Alternatively, to build with Qt 4 you need the following:
121     sudo apt-get install libqt4-dev libprotobuf-dev protobuf-compiler
123 libqrencode (optional) can be installed with:
125     sudo apt-get install libqrencode-dev
127 Once these are installed, they will be found by configure and a bitcoin-qt executable will be
128 built by default.
130 Dependency Build Instructions: Fedora
131 -------------------------------------
132 Build requirements:
134     sudo dnf install gcc-c++ libtool make autoconf automake openssl-devel libevent-devel boost-devel libdb4-devel libdb4-cxx-devel python3
136 Optional:
138     sudo dnf install miniupnpc-devel
140 To build with Qt 5 (recommended) you need the following:
142     sudo dnf install qt5-qttools-devel qt5-qtbase-devel protobuf-devel
144 libqrencode (optional) can be installed with:
146     sudo dnf install qrencode-devel
148 Notes
149 -----
150 The release is built with GCC and then "strip bitcoind" to strip the debug
151 symbols, which reduces the executable size by about 90%.
154 miniupnpc
155 ---------
157 [miniupnpc](http://miniupnp.free.fr/) may be used for UPnP port mapping.  It can be downloaded from [here](
158 http://miniupnp.tuxfamily.org/files/).  UPnP support is compiled in and
159 turned off by default.  See the configure options for upnp behavior desired:
161         --without-miniupnpc      No UPnP support miniupnp not required
162         --disable-upnp-default   (the default) UPnP support turned off by default at runtime
163         --enable-upnp-default    UPnP support turned on by default at runtime
166 Berkeley DB
167 -----------
168 It is recommended to use Berkeley DB 4.8. If you have to build it yourself,
169 you can use [the installation script included in contrib/](/contrib/install_db4.sh)
170 like so
172 ```shell
173 ./contrib/install_db4.sh `pwd`
176 from the root of the repository.
178 **Note**: You only need Berkeley DB if the wallet is enabled (see the section *Disable-Wallet mode* below).
180 Boost
181 -----
182 If you need to build Boost yourself:
184         sudo su
185         ./bootstrap.sh
186         ./bjam install
189 Security
190 --------
191 To help make your bitcoin installation more secure by making certain attacks impossible to
192 exploit even if a vulnerability is found, binaries are hardened by default.
193 This can be disabled with:
195 Hardening Flags:
197         ./configure --enable-hardening
198         ./configure --disable-hardening
201 Hardening enables the following features:
203 * Position Independent Executable
204     Build position independent code to take advantage of Address Space Layout Randomization
205     offered by some kernels. Attackers who can cause execution of code at an arbitrary memory
206     location are thwarted if they don't know where anything useful is located.
207     The stack and heap are randomly located by default but this allows the code section to be
208     randomly located as well.
210     On an AMD64 processor where a library was not compiled with -fPIC, this will cause an error
211     such as: "relocation R_X86_64_32 against `......' can not be used when making a shared object;"
213     To test that you have built PIE executable, install scanelf, part of paxutils, and use:
215         scanelf -e ./bitcoin
217     The output should contain:
219      TYPE
220     ET_DYN
222 * Non-executable Stack
223     If the stack is executable then trivial stack based buffer overflow exploits are possible if
224     vulnerable buffers are found. By default, bitcoin should be built with a non-executable stack
225     but if one of the libraries it uses asks for an executable stack or someone makes a mistake
226     and uses a compiler extension which requires an executable stack, it will silently build an
227     executable without the non-executable stack protection.
229     To verify that the stack is non-executable after compiling use:
230     `scanelf -e ./bitcoin`
232     the output should contain:
233         STK/REL/PTL
234         RW- R-- RW-
236     The STK RW- means that the stack is readable and writeable but not executable.
238 Disable-wallet mode
239 --------------------
240 When the intention is to run only a P2P node without a wallet, bitcoin may be compiled in
241 disable-wallet mode with:
243     ./configure --disable-wallet
245 In this case there is no dependency on Berkeley DB 4.8.
247 Mining is also possible in disable-wallet mode, but only using the `getblocktemplate` RPC
248 call not `getwork`.
250 Additional Configure Flags
251 --------------------------
252 A list of additional configure flags can be displayed with:
254     ./configure --help
257 Setup and Build Example: Arch Linux
258 -----------------------------------
259 This example lists the steps necessary to setup and build a command line only, non-wallet distribution of the latest changes on Arch Linux:
261     pacman -S git base-devel boost libevent python
262     git clone https://github.com/bitcoin/bitcoin.git
263     cd bitcoin/
264     ./autogen.sh
265     ./configure --disable-wallet --without-gui --without-miniupnpc
266     make check
268 Note:
269 Enabling wallet support requires either compiling against a Berkeley DB newer than 4.8 (package `db`) using `--with-incompatible-bdb`,
270 or building and depending on a local version of Berkeley DB 4.8. The readily available Arch Linux packages are currently built using
271 `--with-incompatible-bdb` according to the [PKGBUILD](https://projects.archlinux.org/svntogit/community.git/tree/bitcoin/trunk/PKGBUILD).
272 As mentioned above, when maintaining portability of the wallet between the standard Bitcoin Core distributions and independently built
273 node software is desired, Berkeley DB 4.8 must be used.
276 ARM Cross-compilation
277 -------------------
278 These steps can be performed on, for example, an Ubuntu VM. The depends system
279 will also work on other Linux distributions, however the commands for
280 installing the toolchain will be different.
282 Make sure you install the build requirements mentioned above.
283 Then, install the toolchain and curl:
285     sudo apt-get install g++-arm-linux-gnueabihf curl
287 To build executables for ARM:
289     cd depends
290     make HOST=arm-linux-gnueabihf NO_QT=1
291     cd ..
292     ./configure --prefix=$PWD/depends/arm-linux-gnueabihf --enable-glibc-back-compat --enable-reduce-exports LDFLAGS=-static-libstdc++
293     make
296 For further documentation on the depends system see [README.md](../depends/README.md) in the depends directory.
298 Building on FreeBSD
299 --------------------
301 (Updated as of FreeBSD 11.0)
303 Clang is installed by default as `cc` compiler, this makes it easier to get
304 started than on [OpenBSD](build-openbsd.md). Installing dependencies:
306     pkg install autoconf automake libtool pkgconf
307     pkg install boost-libs openssl libevent
308     pkg install gmake
310 You need to use GNU make (`gmake`) instead of `make`.
311 (`libressl` instead of `openssl` will also work)
313 For the wallet (optional):
315     ./contrib/install_db4.sh `pwd`
316     setenv BDB_PREFIX $PWD/db4
318 Then build using:
320     ./autogen.sh
321     ./configure BDB_CFLAGS="-I${BDB_PREFIX}/include" BDB_LIBS="-L${BDB_PREFIX}/lib -ldb_cxx"
322     gmake
324 *Note on debugging*: The version of `gdb` installed by default is [ancient and considered harmful](https://wiki.freebsd.org/GdbRetirement).
325 It is not suitable for debugging a multi-threaded C++ program, not even for getting backtraces. Please install the package `gdb` and
326 use the versioned gdb command e.g. `gdb7111`.