How to Compile libspex in Ubuntu - SpaceXpanse/Documentation GitHub Wiki
How to Compile libspex in Ubuntu 20.04.3
This will help you to compile libspex in Ubuntu so you can use it in other tutorials and in your own games.
Most dependencies can simply be installed, but some you will need to build and install from source.
You can optionally download the install-libspex.sh script and run it. It runs the same commands as below, but will prompt you to continue at each new stage.
Prepare to Build and Install libspex
The following build instructions assume a fresh installation of Ubuntu 20.04.3 LTS.
NOTE: For the most current information, refer to the libspex repository here:
https://github.com/spacexpanse/libspex
Update and Upgrade Ubuntu
sudo apt-get -y update
You can upgrade, but it's not required, and was not used for this build.
sudo apt-get upgrade
Install Prerequisites & Dependencies with apt
The following will install most dependencies for you. Some others must be built from source.
sudo apt-get -y install build-essential libargtable2-dev libzmq3-dev zlib1g-dev libsqlite3-dev liblmdb-dev libgoogle-glog-dev libgflags-dev libprotobuf-dev protobuf-compiler python3 python-protobuf autoconf autoconf-archive automake cmake git libtool pkg-config libcurl4-openssl-dev libssl-dev libmicrohttpd-dev make
Build and Install Bitcoin-Core libsecp256k1
The Bitcoin-Core libsecp256k1 library is an optimised C library for ECDSA signatures and secret/public key operations on curve secp256k1.
cd ~/
git clone https://github.com/bitcoin-core/secp256k1.git
cd secp256k1
./autogen.sh
./configure --disable-tests --disable-benchmark \
--enable-module-recovery
make
sudo make install
Build Googletest from Source
googletest must be built from source.
cd ~/
git clone https://github.com/google/googletest
cd googletest
cmake .
make -j4
sudo make install/strip
Build and Install SpaceXpanse Eth-Utils
The SpaceXpanse Eth-Utils library is a small C++ library that implements basic building blocks for working with Ethereum from C++.
cd ~/
git clone https://github.com/spacexpanse/eth-utils.git
cd eth-utils
./autogen.sh
./configure
make -j4
sudo make install
Build and Install JSONCPP from Source
libspex requires JSONCPP v1.7.5 or higher, but only v1.7.4 is available to install via apt.
Further, the build process is somewhat odd, so make certain to follow the instructions below, or ensure that any changes you make don't break the libspex build process.
Specifically, v1.9.4 has a broken pkg-config file which must be specifically fixed. The following is currently a "hack" until a new version is released. You can refer to https://github.com/spacexpanse/libspex/blob/ubuntu-build/Dockerfile for version updates.
cd ~/
mkdir jsoncpp && cd jsoncpp
git clone -b 1.9.4 https://github.com/open-source-parsers/jsoncpp .
git config user.email "[email protected]"
git config user.name "Cherry Picker"
git cherry-pick ac2870298ed5b5a96a688d9df07461b31f83e906
cmake . -DJSONCPP_WITH_PKGCONFIG_SUPPORT=ON -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=OFF
make -j4
sudo make install/strip
Build JSON-RPC-CPP from Source
JSON-RPC-CPP must be built from source because the available packages are not fresh enough. Specifically, they must include commit 4f24acaf4c6737cd07d40a02edad0a56147e0713.
cd ~/
git clone https://github.com/cinemast/libjson-rpc-cpp
cd libjson-rpc-cpp
cmake . -DREDIS_SERVER=NO -DREDIS_CLIENT=NO -DCOMPILE_TESTS=NO -DCOMPILE_EXAMPLES=NO -DWITH_COVERAGE=NO
make -j4
sudo make install/strip
Install ZMQ C++ Bindings from Source (CPPZMQ)
The following will install the ZMQ C++ bindings.
cd ~/
git clone -b v4.7.1 https://github.com/zeromq/cppzmq
cd cppzmq
sudo cp zmq.hpp /usr/local/include
Clean Up and Make All Installed Dependencies Visible
The following is a clean-up step and will make our installed dependencies visible for when we build libspex.
sudo ldconfig
Build libspex
With the above accomplished, building and installing libspex is simple and straight forward.
cd ~/
git clone https://github.com/spacexpanse/libspex.git
cd ~/libspex
./autogen.sh
./configure
make -j4
sudo make install
Clean Up and Make libspex Visible
Similar to the clean-up step above, this does the same and will make libspex visible for when you write your GSP.
sudo ldconfig
CONGRATULATIONS!
Congratulations! You've just built and installed libspex. You can now proceed on to the Hello World in C++ tutorial where we'll put libspex to good use!
Update libspex
We update libspex periodically. If you wish to update your build, enter the following into a terminal.
cd ~/libspex
git pull
make clean
./autogen.sh
./configure
make -j4
sudo make install
sudo ldconfig
You're now up-to-date with the latest version!
NOTE: Should the update build break, refer to the libspex repository as it is always up-to-date:
https://github.com/spacexpanse/libspex
You can also refer to the libspex Docker build file for further specifics:
https://github.com/spacexpanse/libspex/blob/ubuntu-build/Dockerfile