How to compile EOS on clean CentOS system

in #eos6 years ago

There is a lot of posts about how to compile EOS on MacOS and Ubuntu, and the EOS offical github site has given a complete compile procedure guidence & automatic scripts to help the developers.
However the choice of operting system is subjected to the actual cluster we use in production environment, and the official did not give a clue how to compile on different systems. According to my own compile practice, there are a lot of bugs and traps that need to be avoid when you compile the EOS. To help the developers who are anxious to experience the EOS on their prefered operating system, I write the following article to demonstrate how I compile on CentOS 7 and how to avoid the traps that hidden under the offical guide.

1. Hardware and System requirements

Due to the requirements of building LLVM WebAssembly,the host must have 10GB free space and the RAM need to be greater than 16GB, multiple cpu cores is suggested.

The operating system we use is CentOS 7.4 , you may choose other Redhat releases.

2. Basic compile environment requirement.

According to the description on EOS.IO github official site,the EOS project is composed on C++14 stander, the default compile come with CentOS 7 is GNU 4.8.5, thus we need to manual choose different repos to install higher verison of GNU compile toolchain. Besides, the CMake version in CentOS 7 official site is a bit old, we need to install the newest Cmake manually.

export BUILD_TEMP=${HOME}/tmp
mkdir ${BUILD_TEMP}

##GNU C++ 6.3.1
sudo yum install -y centos-release-scl
sudo yum install -y devtoolset-6

##CMake 3.10.2

export BUILD_TEMP=${HOME}/tmp
mkdir ${BUILD_TEMP}

cd  ${BUILD_TEMP}
mkdir ${HOME}/opt
curl -L https://cmake.org/files/v3.10/cmake-3.10.2-Linux-x86_64.tar.gz -o cmake-3.10.2-Linux-x86_64.tar.gz
tar -zxf cmake-3.10.2-Linux-x86_64.tar.gz -C ${HOME}/opt

export PATH=$PATH:/opt/rh/devtoolset-6/root/bin/:${HOME}/opt/cmake-3.10.2-Linux-x86_64/bin/

##Other compile tool chain
sudo yum install -y git autoconf automake libtool doxygen ocaml  gmp-devel python-devel bzip2-devel openssl-devel libicu-devel bzip2 wget

3. Compile the dependancy of EOS.IO

According to the official site, compile EOS.IO requires following components:

  • Boost 1.64
  • secp256k1-zkp
  • Binaryen
  • LLVM 4.0 with WebAssembly(On actual compile environment, you also have to compile X86 target for a clean CentOS installation)

3.1. Compile Boost

export BOOST_ROOT=${HOME}/opt/boost_1_64_0
cd  ${BUILD_TEMP}
curl -L https://sourceforge.net/projects/boost/files/boost/1.64.0/boost_1_64_0.tar.bz2 > boost_1.64.0.tar.bz2
tar xvf boost_1.64.0.tar.bz2
cd boost_1_64_0/
./bootstrap.sh "--prefix=$BOOST_ROOT"
./b2 install

3.2. Compile secp256k1-zkp

cd  ${BUILD_TEMP}
git clone https://github.com/cryptonomex/secp256k1-zkp.git
cd secp256k1-zkp
./autogen.sh && ./configure
make
sudo make install

3.3. Compile Binaryen

cd  ${BUILD_TEMP}
git clone https://github.com/WebAssembly/binaryen
cd binaryen
git checkout tags/1.37.14
cmake . && make -j 4
sudo make install

3.4. Compile LLVM WebAssembly+ Host Target

  • TRAP 1
    Due the EOS need LLVM to compile C++ to WebAssembly, the frontend of Clang and WebAssembly are both required, the official compile guidance only compile the WebAssembly target (I assume that is based on the clang is already installed on the ubuntu system,so the auther omitted it when compile LLVM for WebAssembly.), when we compile the LLVM wtih GNU compiler we need to both compile the WebAssembly and X86 target (which is achived by adding parameter DLLVM_TARGETS_TO_BUILD='host' to the cmake configuration), otherwise we would encounter missing LLVMX86****.so error when you compile EOS.
  • TRAP 2
    At current, the EOS only support LLVM of version 4.0,which is achived by clone branch 40 from llvm mirror site, DO NOT directlly pull the latest source from github.
  • TRAP 3
    You have to enable RTTI when you compile, otherwise you may encounter error like typeof ** undefine when you compile EOS. You can avoid this error by add parameter DLLVM_ENABLE_RTTI=ON to the cmake configuration.
cd  ${BUILD_TEMP}

mkdir ${BUILD_TEMP}/wasm-compiler/build -p
cd ${BUILD_TEMP}/wasm-compiler
git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/llvm.git
cd llvm/tools
git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/clang.git
cd ${BUILD_TEMP}/wasm-compiler/build
cmake -G "Unix Makefiles" -DLLVM_ENABLE_RTTI=ON -DLLVM_TARGETS_TO_BUILD='host' -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly -DCMAKE_BUILD_TYPE=Release ../llvm
sudo make -j4 install

export WASM_LLVM_CONFIG=/usr/local/bin/llvm-config

4. Compile EOS

Finally, when you completed the all the dependancy compilation, you may proceed to compile the EOS source now.

cd ${BUILD_TEMP}
git clone https://github.com/eosio/eos --recursive
mkdir -p ${BUILD_TEMP}/eos/build && cd ${BUILD_TEMP}/eos/build
cmake -DBOOST_INCLUDEDIR=${BOOST_ROOT}/include/boost \
-DBOOST_LIBRARYDIR=${BOOST_ROOT}/lib  ..
make -j4

5. Run your first EOS node!

Please refer to Creating and launching a single-node testnet.

Sort:  

Part 4, always got errors to run make -j4 command: /root/tmp/eos/libraries/fc/include/fc/utility.hpp:63:3: error: body of constexpr function ‘constexpr std::size_t fc::const_strlen(const char*)’ not a return-statement

Any ideas? my gcc version is 4.8.5, seems I have to upgrade gcc with higher version, right?

Coin Marketplace

STEEM 0.28
TRX 0.12
JST 0.033
BTC 69995.16
ETH 3735.97
USDT 1.00
SBD 3.74