安装EOS合约工具eosio.cdt

安装:

安装完之后 会产生 eosio-cpp_, eosio-cceosio-ldeosio-pp, and _eosio_abigen (These are the C++ compiler, C compiler, linker, postpass tool and ABI generator.) 这些交互工具。

// step 1
$ git clone --recursive https://github.com/eosio/eosio.cdt

PS:整个克隆过程很慢,如果中断进入项目根目录,执行git submodule update --init --recursive继续下载。

// step 2
// ./build.sh <CORE_SYMBOL> coresymbol可以理解为链名称 这里用eos
$ ./build.sh EOS

build完成之后会出现以下界面:

  ___           ___           ___                       ___
     /  /         /  /         /  /        ___          /  /
    /  /:/_       /  /::       /  /:/_      /  /        /  /::
   /  /:/ /     /  /:/:     /  /:/ /    /  /:/       /  /:/:
  /  /:/ /:/_   /  /:/  :   /  /:/ /::  /__/::      /  /:/  :
 /__/:/ /:/ / /__/:/ \__: /__/:/ /:/: \__/:\__  /__/:/ \__:
   :/:/ /:/   : /  /:/   :/:/~/:/      :/   : /  /:/
    ::/ /:/     :  /:/     ::/ /:/      \__::/    :  /:/
     :/:/       :/:/     \__/ /:/       /__/:/      :/:/
      ::/         ::/        /__/:/        \__/        ::/
     \__/         \__/         \__/                     \__/
For more information:
EOSIO website: https://eos.io

 安装:

// step 3
sudo ./install.sh

安装完后 同样会出现安装成功画面, 这一步install会将下列可执行工具连接到 bin目录下

llvm-ranlib
llvm-ar
llvm-objdump
llvm-readelf
eosio-cc
eosio-cpp
eosio-ld
eosio-pp
eosio-abigen
wasm2wat
wat2wasm

编译:

在路径eosio.cdt/examples 有hello合约的示例

#include <eosiolib/eosio.hpp>
#include <eosiolib/print.hpp>

using namespace eosio;

class hello : public eosio::contract {
  public:
      using contract::contract;

      [[eosio::action]]
      void hi( name user ) {
         print("Hello World",name{user});
      }
};
EOSIO_DISPATCH( hello, (hi))

1 编译wasm文件

$ eosio-cpp hello.cpp -o hello.wasm

2 编译abi文件

// 1 在编译wasm文件的同时加上--abigen flag可以同时编译abi文件
$ eosio-cpp hello.cpp -o hello.wasm --abigen
// 2 直接使用eosio-abigen 编译
$ eosio-abigen hello.cpp --output=hello.abi

  


原文地址:https://www.cnblogs.com/zhangmingcheng/p/11532048.html