Blockchain By Example
上QQ阅读APP看书,第一时间看更新

Building Bitcoin Core

As the dependencies are installed, we can build the code using autotools by running these commands in succession as follows:

 ./autogen.sh
./configure --with-gui=qt5 --enable-debug
sudo make

Pay attention to the space and double dash in front of both the options: with-gui and enable-debug.

It's common to supply some options to the configure command to change the final location of the executable program. You can explore the different possible options in the official documentation: https://github.com/bitcoin/bitcoin/blob/master/doc/build-unix.md.

As you may have noticed, we passed the configure file two arguments: --with-gui=qt5 to build the graphical interface, and --enable-debug to produce better debugging builds. If you want to build only a headless Bitcoin client, use --without-gui.

In order to accelerate the building process, you can skip running the tests by specifying the --disable-tests argument.

After running the make command, the initial compile will take quite a long time. Think about taking a coffee.

If all the dependencies have been installed correctly, a test compilation should be achieved successfully at the end of the compilation process. If you got an error somewhere, have a look at the compilation output to spot the error.

Alternatively, you can run qmake, which is the qt make tool, before running make, or you can install Qt Creator and open the bitcoin-qt.pro file located under the  contrib folder.

Now that the software is built and ready to run, you can optionally install it by running the following command:

sudo make install

This will add the Bitcoin commands to your PATH so that you can simply run bitcoin-qt or bitcoind to start the Bitcoin client without specifying the binary location. Keep in mind that you have to rerun make install each time you edit and compile your code in order to update your client.

Congratulations! You have compiled Bitcoin successfully from its source code.