汪晓明对区块链、以太坊的思考

记录创业、生活的所思所感,探讨去中心化思想,推动区块链的发展。

我推出了《VIP区块链技术开发视频》和电子书《深入浅出以太坊》

以太坊连载(八):C++客户端的安装与定制(二)

从源安装客户端

概览

cpp-ethereum 代码库在几个Git库中传播,库在Git上被分组为webthree-umbrella库下的子模块。

我们用一般的CMake编译系统来生成平台特定的架构文件,这意味着工作流程和你用的任何操作系统都非常类似:

  • 安装编译工具和外部程序包(这些是平台独立的)
  • 从webthree-umbrella git库克隆源代码
  • 运行CMake来生成编译文件(makefile,Visual Studio解决方案等)
  • 编译

特定操作系统安装说明

为Linux创建 注意 —— 通过从源建立和禁用 VMJIT及其他特征,也能够让客户端适用于32位 Ubuntu。我们可能会接受 pull请求来增加这样的支持,但不会投入任何时间来专门开发支持 Ubuntu 32位架构。

Linux有个发行版特定程序包系统步骤的幻灯片,这是我们在开始从源建立之前要做的第一件事。下面的章节试图体现这些步骤。如果你正在使用不同的发行版和hit版本,请告诉我们。

克隆资源库 要克隆源代码,请执行以下指令:

git clone —recursive https://github.com/ethereum/webthree-umbrella.git

安装依赖(发行版特定)

为Ubuntu安装依赖

Ubuntu Trusty Tahr (14.04) 步骤:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
sudo apt-add-repository ppa:george-edison55/cmake-3.x
sudo apt-get -y update
sudo apt-get -y install language-pack-en-base
sudo dpkg-reconfigure locales
sudo apt-get -y install software-properties-common
sudo add-apt-repository "deb http://llvm.org/apt/trusty/ llvm-toolchain-trusty-3.7 main"
wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get -y update
sudo apt-get -y install llvm-3.7-dev
sudo add-apt-repository -y ppa:ethereum/ethereum-qt
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo add-apt-repository -y ppa:ethereum/ethereum-dev
sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y install build-essential git cmake libboost-all-dev libgmp-dev \
libleveldb-dev libminiupnpc-dev libreadline-dev libncurses5-dev \
libcurl4-openssl-dev libcryptopp-dev libmicrohttpd-dev libjsoncpp-dev \
libargtable2-dev libedit-dev mesa-common-dev ocl-icd-libopencl1 opencl-headers \
libgoogle-perftools-dev qtbase5-dev qt5-default qtdeclarative5-dev \
libqt5webkit5-dev libqt5webengine5-dev ocl-icd-dev libv8-dev libz-dev
sudo apt-get -y install libjson-rpc-cpp-dev
sudo apt-get -y install qml-module-qtquick-controls qml-module-qtwebengine

Ubuntu Utopic Unicorn (14.10) 步骤:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

sudo apt-get -y update
sudo apt-get -y install language-pack-en-base
sudo dpkg-reconfigure locales
sudo apt-get -y install software-properties-common
sudo add-apt-repository "deb http://llvm.org/apt/utopic/ llvm-toolchain-utopic-3.7 main"
wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get -y update
sudo apt-get -y install llvm-3.7-dev
sudo add-apt-repository -y ppa:ethereum/ethereum-qt
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo add-apt-repository -y ppa:ethereum/ethereum-dev
sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y install build-essential git cmake libboost-all-dev libgmp-dev \
libleveldb-dev libminiupnpc-dev libreadline-dev libncurses5-dev \
libcurl4-openssl-dev libcryptopp-dev libmicrohttpd-dev libjsoncpp-dev \
libargtable2-dev libedit-dev mesa-common-dev ocl-icd-libopencl1 opencl-headers \
libgoogle-perftools-dev qtbase5-dev qt5-default qtdeclarative5-dev \
libqt5webkit5-dev libqt5webengine5-dev ocl-icd-dev libv8-dev libz-dev
sudo apt-get -y install libjson-rpc-cpp-dev
sudo apt-get -y install qml-module-qtquick-controls qml-module-qtwebengine

Ubuntu Vivid Vervet (15.04) 步骤:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
sudo apt-get -y update
sudo apt-get -y install language-pack-en-base
sudo dpkg-reconfigure locales
sudo apt-get -y install software-properties-common
sudo add-apt-repository "deb http://llvm.org/apt/vivid/ llvm-toolchain-vivid-3.7 main"
wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get -y update
sudo apt-get -y install llvm-3.7-dev
sudo add-apt-repository -y ppa:ethereum/ethereum-qt
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo add-apt-repository -y ppa:ethereum/ethereum-dev
sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y install build-essential git cmake libboost-all-dev libgmp-dev \
libleveldb-dev libminiupnpc-dev libreadline-dev libncurses5-dev \
libcurl4-openssl-dev libcryptopp-dev libmicrohttpd-dev libjsoncpp-dev \
libargtable2-dev libedit-dev mesa-common-dev ocl-icd-libopencl1 opencl-headers \
libgoogle-perftools-dev qtbase5-dev qt5-default qtdeclarative5-dev \
libqt5webkit5-dev libqt5webengine5-dev ocl-icd-dev libv8-dev libz-dev
sudo apt-get -y install libjson-rpc-cpp-dev
sudo apt-get -y install qml-module-qtquick-controls qml-module-qtwebengine

Ubuntu WilyWerewolf (15.10) 步骤:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
sudo apt-get -y update
sudo apt-get -y install language-pack-en-base
sudo dpkg-reconfigure locales
sudo apt-get -y install software-properties-common
sudo add-apt-repository "deb http://llvm.org/apt/wily/ llvm-toolchain-wily-3.7 main"
wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get -y update
sudo apt-get -y install llvm-3.7-dev
sudo add-apt-repository -y ppa:ethereum/ethereum-qt
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo add-apt-repository -y ppa:ethereum/ethereum-dev
sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y install build-essential git cmake libboost-all-dev libgmp-dev \
libleveldb-dev libminiupnpc-dev libreadline-dev libncurses5-dev \
libcurl4-openssl-dev libcryptopp-dev libmicrohttpd-dev libjsoncpp-dev \
libargtable2-dev libedit-dev mesa-common-dev ocl-icd-libopencl1 opencl-headers \
libgoogle-perftools-dev qtbase5-dev qt5-default qtdeclarative5-dev \
libqt5webkit5-dev libqt5webengine5-dev ocl-icd-dev libv8-dev libz-dev
sudo apt-get -y install libjsonrpccpp-dev
sudo apt-get -y install qml-module-qtquick-controls qml-module-qtwebengine

Ubuntu Xenial Xerus (16.04) 步骤:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
sudo apt-get -y update
sudo apt-get -y install language-pack-en-base
sudo dpkg-reconfigure locales
sudo apt-get -y install software-properties-common
sudo apt-get -y install llvm-3.7-dev
sudo add-apt-repository -y ppa:ethereum/ethereum-qt
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo add-apt-repository -y ppa:ethereum/ethereum-dev
sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y install build-essential git cmake libboost-all-dev libgmp-dev \
libleveldb-dev libminiupnpc-dev libreadline-dev libncurses5-dev \
libcurl4-openssl-dev libcryptopp-dev libmicrohttpd-dev libjsoncpp-dev \
libargtable2-dev libedit-dev mesa-common-dev ocl-icd-libopencl1 opencl-headers \
libgoogle-perftools-dev qtbase5-dev qt5-default qtdeclarative5-dev \
libqt5webkit5-dev libqt5webengine5-dev ocl-icd-dev libv8-dev libz-dev
sudo apt-get -y install libjsonrpccpp-dev
sudo apt-get -y install qml-module-qtquick-controls qml-module-qtwebengine \
qml-module-qtquick-privatewidgets qml-module-qtquick-dialogs \
qml-module-qt-labs-settings qml-module-qtgraphicaleffects

为Fedora安装依赖

Fedora 20 步骤:

1
2
3
4
5
yum install git automake autoconf libtool cmake gcc gcc-c++ xkeyboard-config \
leveldb-devel boost-devel gmp-devel cryptopp-devel miniupnpc-devel \
qt5-qtbase-devel qt5-qtdeclarative-devel qt5-qtquick1-devel qt5-qtwebkit-devel \
mesa-dri-drivers snappy-devel ncurses-devel readline-devel curl-devel \
python-devel

Fedora 21 步骤:

1
2
3
4
5
yum install git automake autoconf libtool cmake gcc gcc-c++ xkeyboard-config \
leveldb-devel boost-devel gmp-devel cryptopp-devel miniupnpc-devel \
qt5-qtbase-devel qt5-qtdeclarative-devel qt5-qtquick1-devel qt5-qtwebkit-devel \
mesa-dri-drivers snappy-devel ncurses-devel readline-devel curl-devel \
python-devel jsoncpp-devel argtable-devel

从github建立json-rpc作为每个https://github.com/ethereum/cpp-ethereum/issues/617:

1
2
3
4
5
6
7
8
git clone https://github.com/cinemast/libjson-rpc-cpp
cd libjson-rpc-cpp
git checkout tags/v0.3.2
mkdir -p build
cd build
cmake .. && make
sudo make install
sudo ldconfig

Fedora 22 Fedora 22依赖可能会比已经安装的更多:

1
2
3
4
dnf install git automake autoconf libtool cmake gcc gcc-c++ xkeyboard-config \
leveldb-devel boost-devel gmp-devel cryptopp-devel miniupnpc-devel \
mesa-dri-drivers snappy-devel ncurses-devel readline-devel curl-devel \
python-devel jsoncpp-devel argtable-devel

安装 gcc 4.9版本!Fedora 22 和一个不同的编译器 (CC v5.3)一起。它 不能编译 webthreeumbrella,所以我从SRC安装了 gcc 4.9版本!

检查一下你有可用的 gcc4.9安装在/usr/local ,我把它安装在了 /home/app/gcc49,你可以自己选择在google上阅读说明怎么编译 gcc! 以后在每个 cmake之前,你都要这样用gcc4.9编译 webthree-umbrella所需的所有东西:

1
2
export CXX=/home/app/gcc49/bin/g++
export CC=/home/app/gcc49/bin/gcc

有了这个,你用 gcc4.9而不是和发行版F22一起的来编译。不推荐卸载和你发行版一起的编译器!你也可以用符号链接来工作。

从 Fedora COPR REPO LLVM3.7安装,使用:

1
2
dnf copr enable alonid/llvm-3.7
dnf install llvm-3.7 llvm-3.7-devel llvm-3.7-static llvm-3.7-libs

我必须要这样做是因为 Fedora 22从股票资源库和 llvm-3.5一起!可能也有其他解决方法,但是这个方法对我来说管用。 从 SRC安装CryptoPP https://github.com/weidai11/cryptopp CRYPTOPP_5_6_2:

1
2
3
4
5
6
7
8
9
10
git clone https://github.com/weidai11/cryptopp
cd cryptopp
git checkout release/CRYPTOPP_5_6_2
mkdir build
cd build
export CXX=/home/app/gcc49/bin/g++ <- be sure to compile with gcc4.9
export CC=/home/app/gcc49/bin/gcc <- be sure to compile with gcc4.9
cmake ..
make
make install

从COPR “dnf copr enable @kdesig/Qt5”安装QT5,更新的QT5版本:

1
dnf install qt5-*

这应该在 COPR repo安装QT5 5.6.0 版本。 其他用户的程序包,我没有测试。 从 https://github.com/qtproject/qtwebengine 安装 qtwebengine,我安装5.6.0 版本,其他的也有用,找找看 :D

1
2
3
4
5
6
git clone https://github.com/qtproject/qtwebengine
cd qtwebengine
git checkout release/v5.6.0
qmake-qt5 <- in other distros its just called qmake in fedora 22 qmake-qt5
make
make install

从github安装json-rpc https://github.com/ethereum/cpp-ethereum/issues/617%EF%BC%9A

1
2
3
4
5
6
7
8
9
10
git clone https://github.com/cinemast/libjson-rpc-cpp
cd libjson-rpc-cpp
git checkout tags/v0.4.2
mkdir -p build
cd build
export CXX=/home/app/gcc49/bin/g++ <- be sure to compile with gcc4.9
export CC=/home/app/gcc49/bin/gcc <- be sure to compile with gcc4.9
cmake .. && make
sudo make install
sudo ldconfig

确保检查jsonrpcstub是否在控制台有效,输入“jsonrpcstub” 查看是否有回答。如果答案是没有参数或s-l-t,就说明有效,但如果没有得到的文件,你就得把丢失的部分符号连接到libs dir /usr/local/lib64或者usr/local/lib,取决于文件blabla的位置。试着用 “updatedb” 找到然后“locate blabla.so”

现在试着编译,应该会有效,否则就是有丢失的符号连接因为没有这样的易嵌适文件或有一些丢失的数据包,试着用像这样“dnf search packname”或 “dnf list packname”的dnf找到它们。我要说的是这不是个5分钟的webthree-umbrella编译,享受Tflux99。

为OpenSUSE安装依赖

这是为在OpenSUSE上建立最新webthreeumbrella获取所需依赖的方法。它在Leap 42.1上完成了,但是应该有Tumbleweed和13.x可用的同等数据包。 主要资源库提供的第一个依赖:

1
2
3
4
5
6
7
zypper in git automake autoconf libtool cmake gcc gcc-c++ \
xkeyboard-config leveldb-devel boost-devel gmp-devel \
cryptopp-devel libminiupnpc-devel libqt5-qtbase-common-devel \
libqt5-qtdeclarative-devel libQTWebKit-devel libqt5-qtwebengine-devel \
libQt5Concurrent-devel Mesa ncurses-devel readline-devel libcurl-devel \
llvm llvm-clang llvm-clang-devel llvm-devel libLLVM binutils \
libmicrohttp-devel jsoncpp-devel opencl-headers-1.2 zlib-devel

可以用通用的libOpenCL1,但是我只用来自AMD驱动器资源库fglrx64_opencl_SUSE421的AMD 专有包测试过。

这些包裹不在标准的资源库,但是可以用OpenSUSE 创建服务包搜索和YaST 1-Click安装找到:

  • libargtable2-devel
  • libv8-3
  • v8-devel

为OpenSUSE安装依赖 在Arch Linux编译webthree-umbrella需要来自官方资源库和Arch User资源库(AUR)的依赖。要从官方资源库安装,使用pacman。要从AUR安装包裹,有很多可用的AUR助手。 在本指南中,使用的是AUR助手yaourt。

安装依赖

1
2
3
# from official repositories sudo pacman -Sy git base-devel cmake boost crypto++ leveldb llvm miniupnpc
libcl opencl-headers libmicrohttpd qt5-base qt5-webengine
# from AUR yaourt -Sy libjson-rpc-cpp

编译源代码 在这一步,可