You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build-unix.md 11KB

5 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. UNIX BUILD NOTES
  2. ====================
  3. Some notes on how to build Bitcoin Core in Unix.
  4. (for OpenBSD specific instructions, see [build-openbsd.md](build-openbsd.md))
  5. Note
  6. ---------------------
  7. Always use absolute paths to configure and compile bitcoin and the dependencies,
  8. for example, when specifying the path of the dependency:
  9. ../dist/configure --enable-cxx --disable-shared --with-pic --prefix=$BDB_PREFIX
  10. Here BDB_PREFIX must be an absolute path - it is defined using $(pwd) which ensures
  11. the usage of the absolute path.
  12. To Build
  13. ---------------------
  14. ```bash
  15. ./autogen.sh
  16. ./configure
  17. make
  18. make install # optional
  19. ```
  20. This will build bitcoin-qt as well if the dependencies are met.
  21. Dependencies
  22. ---------------------
  23. These dependencies are required:
  24. Library | Purpose | Description
  25. ------------|------------------|----------------------
  26. libssl | Crypto | Random Number Generation, Elliptic Curve Cryptography
  27. libboost | Utility | Library for threading, data structures, etc
  28. libevent | Networking | OS independent asynchronous networking
  29. Optional dependencies:
  30. Library | Purpose | Description
  31. ------------|------------------|----------------------
  32. miniupnpc | UPnP Support | Firewall-jumping support
  33. libdb4.8 | Berkeley DB | Wallet storage (only needed when wallet enabled)
  34. qt | GUI | GUI toolkit (only needed when GUI enabled)
  35. protobuf | Payments in GUI | Data interchange format used for payment protocol (only needed when GUI enabled)
  36. libqrencode | QR codes in GUI | Optional for generating QR codes (only needed when GUI enabled)
  37. univalue | Utility | JSON parsing and encoding (bundled version will be used unless --with-system-univalue passed to configure)
  38. libzmq3 | ZMQ notification | Optional, allows generating ZMQ notifications (requires ZMQ version >= 4.x)
  39. For the versions used in the release, see [release-process.md](release-process.md) under *Fetch and build inputs*.
  40. Memory Requirements
  41. --------------------
  42. C++ compilers are memory-hungry. It is recommended to have at least 1.5 GB of
  43. memory available when compiling Bitcoin Core. On systems with less, gcc can be
  44. tuned to conserve memory with additional CXXFLAGS:
  45. ./configure CXXFLAGS="--param ggc-min-expand=1 --param ggc-min-heapsize=32768"
  46. Dependency Build Instructions: Ubuntu & Debian
  47. ----------------------------------------------
  48. Build requirements:
  49. sudo apt-get install build-essential libtool autotools-dev automake pkg-config libssl-dev libevent-dev bsdmainutils
  50. Options when installing required Boost library files:
  51. 1. On at least Ubuntu 14.04+ and Debian 7+ there are generic names for the
  52. individual boost development packages, so the following can be used to only
  53. install necessary parts of boost:
  54. sudo apt-get install libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-program-options-dev libboost-test-dev libboost-thread-dev
  55. 2. If that doesn't work, you can install all boost development packages with:
  56. sudo apt-get install libboost-all-dev
  57. BerkeleyDB is required for the wallet. db4.8 packages are available [here](https://launchpad.net/~bitcoin/+archive/bitcoin).
  58. You can add the repository and install using the following commands:
  59. sudo add-apt-repository ppa:bitcoin/bitcoin
  60. sudo apt-get update
  61. sudo apt-get install libdb4.8-dev libdb4.8++-dev
  62. Ubuntu and Debian have their own libdb-dev and libdb++-dev packages, but these will install
  63. BerkeleyDB 5.1 or later, which break binary wallet compatibility with the distributed executables which
  64. are based on BerkeleyDB 4.8. If you do not care about wallet compatibility,
  65. pass `--with-incompatible-bdb` to configure.
  66. See the section "Disable-wallet mode" to build Bitcoin Core without wallet.
  67. Optional:
  68. sudo apt-get install libminiupnpc-dev (see --with-miniupnpc and --enable-upnp-default)
  69. ZMQ dependencies:
  70. sudo apt-get install libzmq3-dev (provides ZMQ API 4.x)
  71. Dependencies for the GUI: Ubuntu & Debian
  72. -----------------------------------------
  73. If you want to build Bitcoin-Qt, make sure that the required packages for Qt development
  74. are installed. Either Qt 5 or Qt 4 are necessary to build the GUI.
  75. If both Qt 4 and Qt 5 are installed, Qt 5 will be used. Pass `--with-gui=qt4` to configure to choose Qt4.
  76. To build without GUI pass `--without-gui`.
  77. To build with Qt 5 (recommended) you need the following:
  78. sudo apt-get install libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools libprotobuf-dev protobuf-compiler
  79. Alternatively, to build with Qt 4 you need the following:
  80. sudo apt-get install libqt4-dev libprotobuf-dev protobuf-compiler
  81. libqrencode (optional) can be installed with:
  82. sudo apt-get install libqrencode-dev
  83. Once these are installed, they will be found by configure and a bitcoin-qt executable will be
  84. built by default.
  85. Dependency Build Instructions: Fedora
  86. -------------------------------------
  87. Build requirements:
  88. sudo dnf install gcc-c++ libtool make autoconf automake openssl-devel libevent-devel boost-devel libdb4-devel libdb4-cxx-devel
  89. Optional:
  90. sudo dnf install miniupnpc-devel
  91. To build with Qt 5 (recommended) you need the following:
  92. sudo dnf install qt5-qttools-devel qt5-qtbase-devel protobuf-devel
  93. libqrencode (optional) can be installed with:
  94. sudo dnf install qrencode-devel
  95. Notes
  96. -----
  97. The release is built with GCC and then "strip bitcoind" to strip the debug
  98. symbols, which reduces the executable size by about 90%.
  99. miniupnpc
  100. ---------
  101. [miniupnpc](http://miniupnp.free.fr/) may be used for UPnP port mapping. It can be downloaded from [here](
  102. http://miniupnp.tuxfamily.org/files/). UPnP support is compiled in and
  103. turned off by default. See the configure options for upnp behavior desired:
  104. --without-miniupnpc No UPnP support miniupnp not required
  105. --disable-upnp-default (the default) UPnP support turned off by default at runtime
  106. --enable-upnp-default UPnP support turned on by default at runtime
  107. Berkeley DB
  108. -----------
  109. It is recommended to use Berkeley DB 4.8. If you have to build it yourself:
  110. ```bash
  111. BITCOIN_ROOT=$(pwd)
  112. # Pick some path to install BDB to, here we create a directory within the bitcoin directory
  113. BDB_PREFIX="${BITCOIN_ROOT}/db4"
  114. mkdir -p $BDB_PREFIX
  115. # Fetch the source and verify that it is not tampered with
  116. wget 'http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz'
  117. echo '12edc0df75bf9abd7f82f821795bcee50f42cb2e5f76a6a281b85732798364ef db-4.8.30.NC.tar.gz' | sha256sum -c
  118. # -> db-4.8.30.NC.tar.gz: OK
  119. tar -xzvf db-4.8.30.NC.tar.gz
  120. # Build the library and install to our prefix
  121. cd db-4.8.30.NC/build_unix/
  122. # Note: Do a static build so that it can be embedded into the executable, instead of having to find a .so at runtime
  123. ../dist/configure --enable-cxx --disable-shared --with-pic --prefix=$BDB_PREFIX
  124. make install
  125. # Configure Bitcoin Core to use our own-built instance of BDB
  126. cd $BITCOIN_ROOT
  127. ./autogen.sh
  128. ./configure LDFLAGS="-L${BDB_PREFIX}/lib/" CPPFLAGS="-I${BDB_PREFIX}/include/" # (other args...)
  129. ```
  130. **Note**: You only need Berkeley DB if the wallet is enabled (see the section *Disable-Wallet mode* below).
  131. Boost
  132. -----
  133. If you need to build Boost yourself:
  134. sudo su
  135. ./bootstrap.sh
  136. ./bjam install
  137. Security
  138. --------
  139. To help make your bitcoin installation more secure by making certain attacks impossible to
  140. exploit even if a vulnerability is found, binaries are hardened by default.
  141. This can be disabled with:
  142. Hardening Flags:
  143. ./configure --enable-hardening
  144. ./configure --disable-hardening
  145. Hardening enables the following features:
  146. * Position Independent Executable
  147. Build position independent code to take advantage of Address Space Layout Randomization
  148. offered by some kernels. Attackers who can cause execution of code at an arbitrary memory
  149. location are thwarted if they don't know where anything useful is located.
  150. The stack and heap are randomly located by default but this allows the code section to be
  151. randomly located as well.
  152. On an AMD64 processor where a library was not compiled with -fPIC, this will cause an error
  153. such as: "relocation R_X86_64_32 against `......' can not be used when making a shared object;"
  154. To test that you have built PIE executable, install scanelf, part of paxutils, and use:
  155. scanelf -e ./bitcoin
  156. The output should contain:
  157. TYPE
  158. ET_DYN
  159. * Non-executable Stack
  160. If the stack is executable then trivial stack based buffer overflow exploits are possible if
  161. vulnerable buffers are found. By default, bitcoin should be built with a non-executable stack
  162. but if one of the libraries it uses asks for an executable stack or someone makes a mistake
  163. and uses a compiler extension which requires an executable stack, it will silently build an
  164. executable without the non-executable stack protection.
  165. To verify that the stack is non-executable after compiling use:
  166. `scanelf -e ./bitcoin`
  167. the output should contain:
  168. STK/REL/PTL
  169. RW- R-- RW-
  170. The STK RW- means that the stack is readable and writeable but not executable.
  171. Disable-wallet mode
  172. --------------------
  173. When the intention is to run only a P2P node without a wallet, bitcoin may be compiled in
  174. disable-wallet mode with:
  175. ./configure --disable-wallet
  176. In this case there is no dependency on Berkeley DB 4.8.
  177. Mining is also possible in disable-wallet mode, but only using the `getblocktemplate` RPC
  178. call not `getwork`.
  179. Additional Configure Flags
  180. --------------------------
  181. A list of additional configure flags can be displayed with:
  182. ./configure --help
  183. Setup and Build Example: Arch Linux
  184. -----------------------------------
  185. This example lists the steps necessary to setup and build a command line only, non-wallet distribution of the latest changes on Arch Linux:
  186. pacman -S git base-devel boost libevent python
  187. git clone https://github.com/bitcoin/bitcoin.git
  188. cd bitcoin/
  189. ./autogen.sh
  190. ./configure --disable-wallet --without-gui --without-miniupnpc
  191. make check
  192. Note:
  193. Enabling wallet support requires either compiling against a Berkeley DB newer than 4.8 (package `db`) using `--with-incompatible-bdb`,
  194. or building and depending on a local version of Berkeley DB 4.8. The readily available Arch Linux packages are currently built using
  195. `--with-incompatible-bdb` according to the [PKGBUILD](https://projects.archlinux.org/svntogit/community.git/tree/bitcoin/trunk/PKGBUILD).
  196. As mentioned above, when maintaining portability of the wallet between the standard Bitcoin Core distributions and independently built
  197. node software is desired, Berkeley DB 4.8 must be used.
  198. ARM Cross-compilation
  199. -------------------
  200. These steps can be performed on, for example, an Ubuntu VM. The depends system
  201. will also work on other Linux distributions, however the commands for
  202. installing the toolchain will be different.
  203. Make sure you install the build requirements mentioned above.
  204. Then, install the toolchain and curl:
  205. sudo apt-get install g++-arm-linux-gnueabihf curl
  206. To build executables for ARM:
  207. cd depends
  208. make HOST=arm-linux-gnueabihf NO_QT=1
  209. cd ..
  210. ./configure --prefix=$PWD/depends/arm-linux-gnueabihf --enable-glibc-back-compat --enable-reduce-exports LDFLAGS=-static-libstdc++
  211. make
  212. For further documentation on the depends system see [README.md](../depends/README.md) in the depends directory.