1. 程式人生 > >1.EOS原始碼編譯執行

1.EOS原始碼編譯執行

目前網路上都是針對老版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會報如下錯誤

[email protected]leaks-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耗時最久,最好的辦法是使用vpn,否則真的就是龜速。

最後編譯成功會顯示如下資訊:

測試驗證
[email protected]:/data/d01/data/eos$ export PATH=${HOME}/opt/mongodb/bin:$PATH
[email protected]:/data/d01/data/eos$ /home/ubuntu/opt/mongodb/bin/mongod -f /home/ubuntu/opt/mongodb/mongod.conf &
[1] 10764
[email protected]:/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主要有三個程式:
[email protected]:/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。

啟動nodeos,命令如下
./nodeos -e -p eosio --plugin eosio::chain_api_plugin --plugin eosio::history_api_plugin 

如果不帶引數執行nodeos程式,會如下錯誤

這是因為沒有為nodeos程式配置各種外掛,修改config檔案配置外掛
vi ~/.local/share/eosio/nodeos/config/config.ini

需要修改如下紅色框的內容

重啟啟動nodeos程式,結果如下,可見已經能挖出block了

安裝開發工具
    比如eosiocpp工具,Include, library庫安裝,這些在開發智慧合約時用的上

cd build
sudo make install

EOS原始碼系列
    https://blog.csdn.net/itleaks/article/category/7763923
---------------------
作者:ITleaks
來源:CSDN
原文:https://blog.csdn.net/ITleaks/article/details/80367131
版權宣告:本文為博主原創文章,轉載請附上博文連結!