我的环境是ubuntu14.04,使用如下指令进行编译安装
1,安装开发工具
sudo apt-add-repository "deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-4.0 main"
sudo apt-get update
sudo apt-get install clang-4.0 lldb-4.0 libclang-4.0-dev cmake make \
libbz2-dev libssl-dev libgmp3-dev \
autotools-dev build-essential \
libbz2-dev libicu-dev python-dev \
autoconf libtool git
2,由于我使用的系统时ubuntu14.04,cmake版本默认安装的是3.2.2
需要安装3.4.3版本
wget http://www.cmake.org/files/v3.4/cmake-3.4.3.tar.gz --no-check-certificate
tar xf cmake-3.4.3.tar.gz
cd cmake-3.4.3
./configure
make
sudo apt-get install checkinstall
sudo checkinstall
sudo make install
sudo mv /usr/bin/cmake /usr/bin/cmakebak
sudo ln -s /usr/local/bin/cmake /usr/bin/cmake
3,升级gcc版本,ubuntu14.04默认是gcc4.8的,升级使用gcc7
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-7 g++-7
编译方式有两种
一:自动化编译安装方式:
1,下载源码
git clone https://github.com/eosio/eos --recursive
cd eos
git checkout DAWN-2018-02-14
2,修改~/eos/buid.sh最后几行,修改了CXX_COMPILER和C_COMPILER改为如下:
CXX_COMPILER=g++-7
C_COMPILER=gcc-7
if [ $ARCH == "darwin" ]; then
CXX_COMPILER=clang++
C_COMPILER=clang
fi
# Build EOS
cmake -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_CXX_COMPILER=${CXX_COMPILER} -DCMAKE_C_COMPILER=${C_COMPILER} -DWASM_LLVM_CONFIG=${WASM_LLVM_CONFIG} -DBINARYEN_BIN=${BINARYEN_BIN} -DOPENSSL_ROOT_DIR=${OPENSSL_ROOT_DIR} -DOPENSSL_LIBRARIES=${OPENSSL_LIBRARIES} ..
make -j4
3,执行编译脚本:
cd ~/eos
./build.sh ubuntu full
cd ~/eos/build
sudo make install
二,手动编译,比较麻烦,安装各种依赖
1,安装boost1.66
cd ~
curl -L https://dl.bintray.com/boostorg/release/1.66.0/source/boost_1_66_0.tar.bz2 > boost_1.66.0.tar.bz2
tar xjf boost_1.66.0.tar.bz2
cd boost_1_66_0/
echo "export BOOST_ROOT=$HOME/boost_1_66_0" >> ~/.bash_profile
source ~/.bash_profile
./bootstrap.sh "--prefix=$BOOST_ROOT"
./b2 install
source ~/.bash_profile
2,安装secp256k1-zkp
cd ~
git clone https://github.com/cryptonomex/secp256k1-zkp.git
cd secp256k1-zkp
./autogen.sh
./configure
make
sudo make install
3,需要使用WASM 编译器, EOS 依赖 binaryen
cd ~
git clone https://github.com/WebAssembly/binaryen.git
cd ~/binaryen
git checkout tags/1.37.14
cmake . && make
4,添加BINARYEN_ROOT 到 your .bash_profile:
echo "export BINARYEN_ROOT=~/binaryen" >> ~/.bash_profile
source ~/.bash_profile
5,默认情况下llvm和clang没有包含wasm构建目标,所以需要自己构建
mkdir ~/wasm-compiler
cd ~/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 ..
mkdir build
cd build
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=.. -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly -DCMAKE_BUILD_TYPE=Release ../
make -j4 install
6,编译eos源码
cd ~
git clone https://github.com/eosio/eos --recursive
mkdir -p ~/eos/build && cd ~/eos/build
cmake -DCMAKE_CXX_COMPILER=g++-7 -DCMAKE_C_COMPILER=gcc-7 -DBINARYEN_BIN=~/binaryen/bin -DWASM_ROOT=~/wasm-compiler/llvm -DOPENSSL_LIBRARIES=/lib/x86_64-linux-gnu/ ..
make -j4
错误处理:
1,g++: internal compiler error: Killed (program cc1plus)
解决:主要原因大体上是因为内存不足,有点坑 临时使用交换分区来解决:
sudo dd if=/dev/zero of=/swapfile bs=64M count=16
sudo mkswap /swapfile
sudo swapon /swapfile