[EOS源码分析]1.EOS源码编译运行

 

本文所有实践都是基于EOS dawn-v4.1.0,请切到该分支然后实践

切换命令:git checkout dawn-v4.1.0

    目前网络上都是针对老版EOS2.0源码编译的文章,我在mac上参考这些文章编译,最后发现根本就不对,最新版本只需一条命令(./eosio_build.sh,依赖库会自动安装的)即可。我根据这些文章手动安装的库还导致如下问题,最后大部分时间都花在解决这个问题上。【官网安装文档传送门】

 

ItleaksDeMacbook-Pro:eos itleaks$ ./eosio_build.sh

fatal: destination path 'mongo-cxx-driver' already exists and is not an empty directory.

    Unable to clone MongoDB C++ driver at this time.

    Exiting now.

 

这个问题解决方案如下

sudo rm -rf /tmp/mongo*

cd /path/to/eos

rm -rf build/

git pull

git submodule update --init --recursive

./eosio_build.sh

 

如果还是不行,可以尝试重装brew,具体参考我的这篇博文【mac重装Homebrew】

 

 

如果出现下面的问题

 Failed to find Gettext libintl (missing: Intl_INCLUDE_DIR)

执行下面的命令即可

brew unlink gettext && brew link --force gettext

 

现在开始跟着下面的步骤编译EOS搭建开发环境吧

下载源码

EOS 代码使用了三个子模块

  • 插件管理模块 AppBase
  • 区块链结构模块 ChainBase
  • WASM 模块

git clone https://github.com/eosio/eos --recursive

所以上面需要用recursive,如果没有带有recursive下载了eos,可以通过如下方式下载submodules

cd eos

git submodule update --init --recursive

国内目前从github下载源码速度很慢,可以参考我这篇博文【github访问慢和clone慢解决方案】提速

 

编译

编译其实很简单,就是执行./eosio_build.sh脚本

mac平台编译依赖homebrew工具,所以必须先安装好homebrew工具

    

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

 

如果你的电脑内存<8G会报如下错误

 

itleaks@itleaks-VirtualBox:~/projects/eos$ ./eosio_build.sh

 

    Beginning build version: 1.2

    2018年 05月 18日 星期五 07:13:36 UTC

    User: itleaks

    git head id: 29c30f10650102ffb000bb1a287dc285d582275f

    Current branch: master

 

    ARCHITECTURE: Linux

 

    OS name: Ubuntu

    OS Version: 16.04

    CPU speed: 3095.998Mhz

    CPU cores: 1

    Physical Memory: 1993 Mgb

    Disk install: /dev/sda1

    Disk space total: 47G

    Disk space available: 31G

    Your system must have 7 or more Gigabytes of physical memory installed.

    Exiting now.

 

 

如果你想绕开这个限制,可以修改相应的脚本文件

VirtualBox:~/projects/eos$ grep "Your system must have" . -rn

./scripts/eosio_build_ubuntu.sh:28:        printf "\\tYour system must have 7 or more Gigabytes of physical memory installed.\\n"

./scripts/eosio_build_darwin.sh:29:        echo "Your system must have 7 or more Gigabytes of physical memory installed."

./scripts/eosio_build_fedora.sh:25:        printf "\\tYour system must have 7 or more Gigabytes of physical memory installed.\\n"

./scripts/eosio_build_amazon.sh:21:        printf "\\tYour system must have 7 or more Gigabytes of physical memory installed.\\n"

./scripts/eosio_build_centos.sh:26:        printf "\\n\\tYour system must have 7 or more Gigabytes of physical memory installed.\\n"

 

比如ubuntu平台就修改./scripts/eosio_build_ubuntu.sh文件,将下面的7000修改即可

 

编译时会自动下载依赖库

 

$./eosio_build.sh

Checking dependencies.

    Checking automake ...          automake NOT found.

    Checking Libtool ...          Libtool NOT found.

    Checking OpenSSL ...          OpenSSL NOT found.

    Checking llvm ...          llvm NOT found.

    Checking wget ...          wget NOT found.

    Checking CMake ...          CMake NOT found.

    Checking GMP ...          GMP NOT found.

    Checking gettext ...          gettext NOT found.

    Checking MongoDB ...          MongoDB NOT found.

    Checking Doxygen ...          Doxygen NOT found.

    Checking Graphviz ...          Graphviz NOT found.

    Checking LCOV ...          LCOV NOT found.

    Checking Python3 ...          python3 NOT found.

 

    The following dependencies are required to install EOSIO.

 

    1. automake\n\t2. Libtool\n\t3. OpenSSL\n\t4. llvm\n\t5. wget\n\t6. CMake\n\t7. GMP\n\t8. gettext\n\t9. MongoDB\n\t10. Doxygen\n\t11. Graphviz\n\t12. LCOV\n\t13. Python 3\n\t

 

    这个依赖库下载过程是非常慢,其中llvm耗时最久,最好的办法是使用,否则真的就是龟速。

 

最后编译成功会显示如下信息:

 

[EOS源码分析]1.EOS源码编译运行_第1张图片

 

测试验证

ubuntu@ip-172-31-28-214:/data/d01/data/eos$ export PATH=${HOME}/opt/mongodb/bin:$PATH

ubuntu@ip-172-31-28-214:/data/d01/data/eos$ /home/ubuntu/opt/mongodb/bin/mongod -f /home/ubuntu/opt/mongodb/mongod.conf &

[1] 10764

ubuntu@ip-172-31-28-214:/data/d01/data/eos$ cd /data/d01/data/eos/build; make test

Running tests...

Test project /data/d01/data/eos/build

      Start  1: test_cypher_suites

1/29 Test  #1: test_cypher_suites ..................   Passed    0.02 sec

      Start  2: validate_simple.token_abi

2/29 Test  #2: validate_simple.token_abi ...........   Passed    0.02 sec

      Start  3: validate_eosio.token_abi

3/29 Test  #3: validate_eosio.token_abi ............   Passed    0.03 sec

      Start  4: validate_eosio.msig_abi

4/29 Test  #4: validate_eosio.msig_abi .............   Passed    0.02 sec

      Start  5: validate_multi_index_test_abi

5/29 Test  #5: validate_multi_index_test_abi .......   Passed    0.03 sec

      Start  6: validate_eosio.system_abi

6/29 Test  #6: validate_eosio.system_abi ...........   Passed    0.02 sec

      Start  7: validate_identity_abi

7/29 Test  #7: validate_identity_abi ...............   Passed    0.03 sec

      Start  8: validate_identity_test_abi

8/29 Test  #8: validate_identity_test_abi ..........   Passed    0.03 sec

      Start  9: validate_stltest_abi

9/29 Test  #9: validate_stltest_abi ................   Passed    0.02 sec

      Start 10: validate_exchange_abi

10/29 Test #10: validate_exchange_abi ...............   Passed    0.02 sec

      Start 11: validate_test.inline_abi

11/29 Test #11: validate_test.inline_abi ............   Passed    0.02 sec

      Start 12: validate_hello_abi

12/29 Test #12: validate_hello_abi ..................   Passed    0.02 sec

      Start 13: validate_asserter_abi

13/29 Test #13: validate_asserter_abi ...............   Passed    0.02 sec

      Start 14: validate_infinite_abi

14/29 Test #14: validate_infinite_abi ...............   Passed    0.03 sec

      Start 15: validate_proxy_abi

15/29 Test #15: validate_proxy_abi ..................   Passed    0.02 sec

      Start 16: validate_test_api_abi

16/29 Test #16: validate_test_api_abi ...............   Passed    0.02 sec

      Start 17: validate_test_api_mem_abi

17/29 Test #17: validate_test_api_mem_abi ...........   Passed    0.02 sec

      Start 18: validate_test_api_db_abi

18/29 Test #18: validate_test_api_db_abi ............   Passed    0.03 sec

      Start 19: validate_test_api_multi_index_abi

19/29 Test #19: validate_test_api_multi_index_abi ...   Passed    0.03 sec

      Start 20: validate_eosio.bios_abi

20/29 Test #20: validate_eosio.bios_abi .............   Passed    0.02 sec

      Start 21: validate_noop_abi

21/29 Test #21: validate_noop_abi ...................   Passed    0.02 sec

      Start 22: validate_dice_abi

22/29 Test #22: validate_dice_abi ...................   Passed    0.02 sec

      Start 23: validate_tic_tac_toe_abi

23/29 Test #23: validate_tic_tac_toe_abi ............   Passed    0.02 sec

      Start 24: validate_payloadless_abi

24/29 Test #24: validate_payloadless_abi ............   Passed    0.02 sec

 

启动节点服务程序

 EOS主要有三个程序:

ubuntu@ip-172-31-28-214:/data/d01/data/eos/build$ ls programs/ -alh

total 52K

drwxrwxr-x  9 ubuntu ubuntu 4.0K May 18 07:45 .

drwxrwxr-x 16 ubuntu ubuntu 4.0K May 18 08:00 ..

drwxrwxr-x  3 ubuntu ubuntu 4.0K May 18 07:52 cleos

drwxrwxr-x  3 ubuntu ubuntu 4.0K May 18 07:50 keosd

drwxrwxr-x  3 ubuntu ubuntu 4.0K May 18 07:53 nodeos

  • cloes:客户端命令行交互模块,用于解析用户命令,根据具体命令请求调用相应的接口,例如查看区块信息、操作钱包等等。
  • nodeos:服务器端,也就是区块生产节点,用于接受客户端的远端请求,并打包区块,主要包含四个插件,chain_plugin、http_plugin、net_plugin、producer_plugin。

  • keosd:钱包管理模块,主要包括三个插件,wallet_plugin、wallet_api_plugin、http_plugin。

[EOS源码分析]1.EOS源码编译运行_第2张图片

 


启动nodeos,命令如下

./nodeos -e -p eosio --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin 

 

如果不带参数执行nodeos程序,会如下错误

 

[EOS源码分析]1.EOS源码编译运行_第3张图片

 

这是因为没有为nodeos程序配置各种插件,修改config文件配置插件

vi ~/.local/share/eosio/nodeos/config/config.ini

 

需要修改如下红色框的内容

重启启动nodeos程序,结果如下,可见已经能挖出block了

[EOS源码分析]1.EOS源码编译运行_第4张图片

安装开发工具

    比如eosiocpp工具,Include, library库安装,这些在开发智能合约时用的上

cd build

sudo make install

 

EOS源码系列

    https://blog.csdn.net/itleaks/article/category/7763923

/********************************

* 本文来自CSDN博主"爱踢门"

* 转载请标明出处:http://blog.csdn.net/itleaks

******************************************/

如果你对EOS,ETH技术及开发感兴趣,请入QQ群讨论: 829789117


如需实时查看最新文章,请关注公众号"区块链斜杠青年",一起探索区块链未来

你可能感兴趣的:(区块链,EOS,EOS源码分析)