How to build BitcoinCore from sources in Debian


BitcoinCore is Bitcoin reference implementation.

We are going to download BitcoinCore source code and then build and install it on a Debian Sid system.

https://github.com/bitcoin/bitcoin/blob/master/doc/build-unix.md


Get Bitcoin source code


First we download source code from BitcoinCore repository by using git:
$ sudo aptitude install git

clone Bitcoin repo:
$ git clone https://github.com/bitcoin/bitcoin
$ cd bitcoin

We have downloaded master development branch. We rather a stable one, e.g: 0.15 one
bitcoin$ git branch
* master

bitcoin$ git remote show
origin

bitcoin$ git remote show origin
* remote origin
Fetch URL: https://github.com/bitcoin/bitcoin
Push URL: https://github.com/bitcoin/bitcoin
HEAD branch: master
Remote branches:
0.10 tracked
0.11 tracked
0.12 tracked
0.13 tracked
0.14 tracked
0.15 tracked
0.8 tracked
0.9 tracked
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)


We change into 0.15 branch:
$ git checkout -b 0.15 --track origin/0.15
Branch '0.15' set up to track remote branch '0.15' from 'origin'.
Switched to a new branch '0.15'


$ git branch
* 0.15
master



Generate configure file


We install some dependencies and execute autogen.sh to generate configure file:
$ sudo aptitude install autoconf libtool pkg-config
$ bash autogen.sh

We are going to compile Bitcoin node in a separate directory bitcoin_build
$ cd ..
$ mkdir bitcoin_build
$ cd bitcoin_build


Install Berkeley database version 4.8


If we install some dependencies more and try to compile:
$ sudo aptitude install gawk
$ sudo aptitude install g++ make
$ ../bitcoin/configure

We get this error:
configure: error: libdb_cxx headers missing, Bitcoin Core requires this library for wallet functionality (--disable-wallet to disable wallet functionality)


It needs Berkeley database version 4.8 for compatibility with old wallet.dat files.

https://github.com/bitcoin/bitcoin/issues/3686
https://talk.peercoin.net/t/xolominer-how-to-compile-and-run-in-linux/825


We download Berkeley database and build it:
$ mkdir bdb-4.8
$ cd bdb_4.8
$ wget http://download.oracle.com/berkeley-db/db-4.8.30.tar.gz
$ tar xvzf db-4.8.30.tar.gz
$ cd db-4.8.30/build_unix/
$ ../dist/configure --enable-cxx


An error happens because a builtin function in gcc has same name as a macro in bdb:
http://rupasundar.blogspot.com.es/2015/02/warning-conflicting-types-for-built-in.html
https://github.com/narkoleptik/os-x-berkeleydb-patch/blob/master/atomic.patch

../dist/../dbinc/atomic.h:179:19: warning: conflicting types for built-in function '__atomic_compare_exchange' [-Wbuiltin-declaration-mismatch]
 static inline int __atomic_compare_exchange(

../dist/../dbinc/atomic.h:147:2: error: incorrect number of arguments to function '__atomic_compare_exchange'
  __atomic_compare_exchange((p), (o), (n))


I rename __atomic_compare_exchange to __atomic_compare_exchange_db:
$ nano ../dbinc/atomic.h

#define atomic_compare_exchange(env, p, o, n)   \
        __atomic_compare_exchange_db((p), (o), (n))


Now we can finish installation of BDB
$ make
$ sudo make install


Once bdb-4.8 is installed we continue with Bitcoin compilation:

We need to tell our system where to find db4.8
$ export BDB_INCLUDE_PATH="/usr/local/BerkeleyDB.4.8/include"
$ export BDB_LIB_PATH="/usr/local/BerkeleyDB.4.8/lib"
$ sudo ln -s /usr/local/BerkeleyDB.4.8/lib/libdb-4.8.so /usr/lib/libdb-4.8.so
$ sudo ln -s /usr/local/BerkeleyDB.4.8/lib/libdb_cxx-4.8.so /usr/lib/libdb_cxx-4.8.so
$ sudo ldconfig

$ cd ~/devel/bitcoin_build$ ../bitcoin/configure
checking for Berkeley DB C++ headers... no
configure: error: libdb_cxx headers missing, Bitcoin Core requires this library for wallet functionality (--disable-wallet to disable wallet functionality)


We will set CPPFLAGS and LDFLAGS variables for the compiler and linker to find BDB headers and libraries.
$ ../bitcoin/configure CPPFLAGS="-I/usr/local/BerkeleyDB.4.8/include -O2" LDFLAGS="-L/usr/local/BerkeleyDB.4.8/lib"


Finish BitcoinCore compilation


We install boost dependency
$ sudo aptitude install libboost-all-dev

For hexdump binary dependency:
$ sudo aptitude install bsdmainutils

SSL dependency:
$ sudo aptitude install openssl libssl-dev

Finally we compile BitcoinCore:
$ ../bitcoin/configure CPPFLAGS="-I/usr/local/BerkeleyDB.4.8/include -O2" LDFLAGS="-L/usr/local/BerkeleyDB.4.8/lib"

$ make

$ sudo make install


Now you can run your BitcoinCore node.
How to run a Bitcoin node in Debian