Ignore GETBLOCKTXN requests for unknown blocks
[bitcoinplatinum.git] / doc / build-unix.md
blobbd89978cc2a74270808eb95cc24d42618021e62d
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 in the release, see [release-process.md](release-process.md) under *Fetch and build inputs*.
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
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. db4.8 packages are available [here](https://launchpad.net/~bitcoin/+archive/bitcoin).
83 You can add the repository and install using the following commands:
85     sudo add-apt-repository ppa:bitcoin/bitcoin
86     sudo apt-get update
87     sudo apt-get install libdb4.8-dev libdb4.8++-dev
89 Ubuntu and Debian have their own libdb-dev and libdb++-dev packages, but these will install
90 BerkeleyDB 5.1 or later, which break binary wallet compatibility with the distributed executables which
91 are based on BerkeleyDB 4.8. If you do not care about wallet compatibility,
92 pass `--with-incompatible-bdb` to configure.
94 See the section "Disable-wallet mode" to build Bitcoin Core without wallet.
96 Optional:
98     sudo apt-get install libminiupnpc-dev (see --with-miniupnpc and --enable-upnp-default)
100 ZMQ dependencies:
102     sudo apt-get install libzmq3-dev (provides ZMQ API 4.x)
104 Dependencies for the GUI: Ubuntu & Debian
105 -----------------------------------------
107 If you want to build Bitcoin-Qt, make sure that the required packages for Qt development
108 are installed. Either Qt 5 or Qt 4 are necessary to build the GUI.
109 If both Qt 4 and Qt 5 are installed, Qt 5 will be used. Pass `--with-gui=qt4` to configure to choose Qt4.
110 To build without GUI pass `--without-gui`.
112 To build with Qt 5 (recommended) you need the following:
114     sudo apt-get install libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools libprotobuf-dev protobuf-compiler
116 Alternatively, to build with Qt 4 you need the following:
118     sudo apt-get install libqt4-dev libprotobuf-dev protobuf-compiler
120 libqrencode (optional) can be installed with:
122     sudo apt-get install libqrencode-dev
124 Once these are installed, they will be found by configure and a bitcoin-qt executable will be
125 built by default.
127 Dependency Build Instructions: Fedora
128 -------------------------------------
129 Build requirements:
131     sudo dnf install gcc-c++ libtool make autoconf automake openssl-devel libevent-devel boost-devel libdb4-devel libdb4-cxx-devel
133 Optional:
135     sudo dnf install miniupnpc-devel
137 To build with Qt 5 (recommended) you need the following:
139     sudo dnf install qt5-qttools-devel qt5-qtbase-devel protobuf-devel
141 libqrencode (optional) can be installed with:
143     sudo dnf install qrencode-devel
145 Notes
146 -----
147 The release is built with GCC and then "strip bitcoind" to strip the debug
148 symbols, which reduces the executable size by about 90%.
151 miniupnpc
152 ---------
154 [miniupnpc](http://miniupnp.free.fr/) may be used for UPnP port mapping.  It can be downloaded from [here](
155 http://miniupnp.tuxfamily.org/files/).  UPnP support is compiled in and
156 turned off by default.  See the configure options for upnp behavior desired:
158         --without-miniupnpc      No UPnP support miniupnp not required
159         --disable-upnp-default   (the default) UPnP support turned off by default at runtime
160         --enable-upnp-default    UPnP support turned on by default at runtime
163 Berkeley DB
164 -----------
165 It is recommended to use Berkeley DB 4.8. If you have to build it yourself:
167 ```bash
168 BITCOIN_ROOT=$(pwd)
170 # Pick some path to install BDB to, here we create a directory within the bitcoin directory
171 BDB_PREFIX="${BITCOIN_ROOT}/db4"
172 mkdir -p $BDB_PREFIX
174 # Fetch the source and verify that it is not tampered with
175 wget 'http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz'
176 echo '12edc0df75bf9abd7f82f821795bcee50f42cb2e5f76a6a281b85732798364ef  db-4.8.30.NC.tar.gz' | sha256sum -c
177 # -> db-4.8.30.NC.tar.gz: OK
178 tar -xzvf db-4.8.30.NC.tar.gz
180 # Build the library and install to our prefix
181 cd db-4.8.30.NC/build_unix/
182 #  Note: Do a static build so that it can be embedded into the executable, instead of having to find a .so at runtime
183 ../dist/configure --enable-cxx --disable-shared --with-pic --prefix=$BDB_PREFIX
184 make install
186 # Configure Bitcoin Core to use our own-built instance of BDB
187 cd $BITCOIN_ROOT
188 ./autogen.sh
189 ./configure LDFLAGS="-L${BDB_PREFIX}/lib/" CPPFLAGS="-I${BDB_PREFIX}/include/" # (other args...)
192 **Note**: You only need Berkeley DB if the wallet is enabled (see the section *Disable-Wallet mode* below).
194 Boost
195 -----
196 If you need to build Boost yourself:
198         sudo su
199         ./bootstrap.sh
200         ./bjam install
203 Security
204 --------
205 To help make your bitcoin installation more secure by making certain attacks impossible to
206 exploit even if a vulnerability is found, binaries are hardened by default.
207 This can be disabled with:
209 Hardening Flags:
211         ./configure --enable-hardening
212         ./configure --disable-hardening
215 Hardening enables the following features:
217 * Position Independent Executable
218     Build position independent code to take advantage of Address Space Layout Randomization
219     offered by some kernels. Attackers who can cause execution of code at an arbitrary memory
220     location are thwarted if they don't know where anything useful is located.
221     The stack and heap are randomly located by default but this allows the code section to be
222     randomly located as well.
224     On an AMD64 processor where a library was not compiled with -fPIC, this will cause an error
225     such as: "relocation R_X86_64_32 against `......' can not be used when making a shared object;"
227     To test that you have built PIE executable, install scanelf, part of paxutils, and use:
229         scanelf -e ./bitcoin
231     The output should contain:
233      TYPE
234     ET_DYN
236 * Non-executable Stack
237     If the stack is executable then trivial stack based buffer overflow exploits are possible if
238     vulnerable buffers are found. By default, bitcoin should be built with a non-executable stack
239     but if one of the libraries it uses asks for an executable stack or someone makes a mistake
240     and uses a compiler extension which requires an executable stack, it will silently build an
241     executable without the non-executable stack protection.
243     To verify that the stack is non-executable after compiling use:
244     `scanelf -e ./bitcoin`
246     the output should contain:
247         STK/REL/PTL
248         RW- R-- RW-
250     The STK RW- means that the stack is readable and writeable but not executable.
252 Disable-wallet mode
253 --------------------
254 When the intention is to run only a P2P node without a wallet, bitcoin may be compiled in
255 disable-wallet mode with:
257     ./configure --disable-wallet
259 In this case there is no dependency on Berkeley DB 4.8.
261 Mining is also possible in disable-wallet mode, but only using the `getblocktemplate` RPC
262 call not `getwork`.
264 Additional Configure Flags
265 --------------------------
266 A list of additional configure flags can be displayed with:
268     ./configure --help
271 Setup and Build Example: Arch Linux
272 -----------------------------------
273 This example lists the steps necessary to setup and build a command line only, non-wallet distribution of the latest changes on Arch Linux:
275     pacman -S git base-devel boost libevent python
276     git clone https://github.com/bitcoin/bitcoin.git
277     cd bitcoin/
278     ./autogen.sh
279     ./configure --disable-wallet --without-gui --without-miniupnpc
280     make check
282 Note:
283 Enabling wallet support requires either compiling against a Berkeley DB newer than 4.8 (package `db`) using `--with-incompatible-bdb`,
284 or building and depending on a local version of Berkeley DB 4.8. The readily available Arch Linux packages are currently built using
285 `--with-incompatible-bdb` according to the [PKGBUILD](https://projects.archlinux.org/svntogit/community.git/tree/bitcoin/trunk/PKGBUILD).
286 As mentioned above, when maintaining portability of the wallet between the standard Bitcoin Core distributions and independently built
287 node software is desired, Berkeley DB 4.8 must be used.
290 ARM Cross-compilation
291 -------------------
292 These steps can be performed on, for example, an Ubuntu VM. The depends system
293 will also work on other Linux distributions, however the commands for
294 installing the toolchain will be different.
296 First install the toolchain:
298     sudo apt-get install g++-arm-linux-gnueabihf
300 To build executables for ARM:
302     cd depends
303     make HOST=arm-linux-gnueabihf NO_QT=1
304     cd ..
305     ./configure --prefix=$PWD/depends/arm-linux-gnueabihf --enable-glibc-back-compat --enable-reduce-exports LDFLAGS=-static-libstdc++
306     make
309 For further documentation on the depends system see [README.md](../depends/README.md) in the depends directory.