A+ A A-

Compiling a wallet

Compiling a wallet, can sometimes be more difficult than it really needs to be.  Sure, we can generally just download the releases and run them, but perhaps they aren't built for our system, and what then?  Well we need to compile them.  This involves cloning the repository, and then running the build process.  Whichever way we do this depends on the particular coin.

There are two ways we can do this, one requires a little more work than the other.  When we started NodeCheck, we were building using all the required dev packages from Ubuntu (for example) being installed.  Documentation varies from one to the next, and so sometimes there was a situation that during the compile process it would stop.  Ah yes, it seems we are missing a dependency.  So we install it based on the error that appeared, and then we continue.  Maybe it would fail again.  There are occasions for example though, that you come across a dependency that isn't available in the Ubuntu repository.  Berkeley DB is one, but a simple PPA add command sorts out thanks to that being available.  But there are some, that sometimes are not available.

This is where the depends directory comes into play.  You can alter the configure command to use this, which means we don't need to utilise the dev packages from the Ubuntu system at all!  Absolutely none of them.  Sure, we need to have the build environment, so you need a minimum set of packages, and then the depends directory for the wallet in question does the rest.  In this instance, you don't have to worry about the build process failing because you didn't install libboost-all-dev for example, or one of the other Ubuntu dev packages.  Because it's all in the depends directory.

Whichever one you choose though, please ensure you do it one way or the other.  If you install the Ubuntu dev packages, then don't build later using the depends directory.  Recently we had an issue with this, and the wallet wasn't running as it should because the wallet was built to use the depends directory, but conflicted with the Ubuntu dev packages that were installed.

So, if you don't want to worry about having to install an Ubuntu dev package later, and aren't sure even what it's called based on the compile error output, then the best way here is just build using the depends directory and forget about attempting to use the dev packages provided in the Ubuntu repositories.  Or Debian, or whichever system you are building on.

And that leads me to this, what do we need to install to successfully compile with the depends directory?  Simple, on Ubuntu in our example, all you need is:

apt install build-essential automake libtool pkg-config

and that is it!  Make sure you did a minimal install of Ubuntu before this without installing any dev packages.  Then when the server is running, just install those four packages.  Then when you are ready to compile, all you need to do is run for example, a script like we have below:

#!/bin/bash
#

# Set number of processors
CPUS=`cat /proc/cpuinfo | grep -ic proc`

# Prepare dependencies
cd depends
make -j2 NO_QT=1
cd ..

# Prep code for compilation
./autogen.sh
./configure --disable-tests --disable-bench --without-gui --prefix `pwd`/depends/x86_64-pc-linux-gnu

# Compile
make -j$CPUS
make install

If you want to compile the QT wallet, then remove two things from the above script.  The first to remove is "NO_QT=1" and the second is lower down "--without-gui".  Then once compile has finished, in depends/x86_64-pc-linux-gnu/bin you will find the binaries that you compiled using the depends directory.  You can then copy these to /usr/local/bin for example and run the wallet you just compiled!