跳到主要内容

编译 Conflux 节点

这里是关于如何从源代码构建Conflux并运行节点的逐步指南。

安装构建依赖​

Conflux requires Rust 1.86, clang, and sqlite to build.

我们推荐通过rustup来安装Rust。 如果您还没有安装rustup或clang,可以这样安装它们:

Linux:​

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# you might need to run
# source "$HOME/.cargo/env"
# to configure your shell
rustup install 1.86

Other dependencies including clang, cmake (version >= 3.12) and sqlite (version >= 3.8.3 and < 4.0) can be installed with:

  • Ubuntu 18.04-22.04:
# Ubuntu 18.04上最新的cmake版本是3.10,因此您需要从Kitware仓库安装它。
# This step is not required on Ubuntu 22.04
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ bionic main' | sudo tee /etc/apt/sources.list.d/kitware.list >/dev/null

sudo apt-get update
sudo apt-get install clang libsqlite3-dev pkg-config libssl-dev cmake
  • CentOS 7 / RHEL:
sudo yum install epel-release
sudo yum install clang gcc gcc-c++ openssl-devel cmake3 wget

# 如果您已经安装了2.8版本的cmake,这可能会失败。
# 您可以选择先卸载cmake。
sudo ln -s /usr/bin/cmake3 /usr/bin/cmake

# CentOS 7上官方的sqlite版本是3.7.17,因此我们需要从源代码安装最新版本。
# 源代码可以从https://www.sqlite.org/download.html下载
wget https://www.sqlite.org/2020/sqlite-autoconf-3320100.tar.gz
tar xfvz sqlite-autoconf-3320100.tar.gz
cd sqlite-autoconf-3320100
./configure
make
sudo make install

OSX:​

curl https://sh.rustup.rs -sSf | sh
# you might need to run
# source "$HOME/.cargo/env"
# to configure your shell
rustup install 1.86

如果您需要使用brew来安装clang,可能需要安装brew:

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

clang随Xcode命令行工具一起提供,也可以通过homebrew安装:

brew install llvm

您还需要使用homebrew安装其他依赖项,并在安装后设置环境变量:

brew install openssl pkg-config cmake bzip2 

Windows​

确保您安装了带有C++支持的Visual Studio 2015。 接下来,从此链接下载并运行rustup安装程序,启动VS2015 x64 Native Tools Command Prompt,并使用以下命令安装并设置msvc工具链:

rustup default stable-x86_64-pc-windows-msvc

clang可以用LLVM安装。 预构建的二进制文件可以从Download LLVM下载。 确保按照指示将LLVM添加到系统PATH中。

确保这些二进制文件在您的PATH中(安装rustup后会显示指令)。 之后,您应该能够从源代码构建Conflux。

从源代码构建​

After installing the dependencies mentioned above, now you can clone our repository and start building the executable binary. The latest mainnet node version is v2.4.1.

# download Conflux code
git clone https://github.com/Conflux-Chain/conflux-rust
cd conflux-rust
git checkout <latest-released-mainnet-version> # checkout to the latest release version

# Usually, you just need the latest source code without the complete history. You can speed up the cloning process with the following command.
git clone -b <latest-released-mainnet-version> --single-branch --depth 1 https://github.com/Conflux-Chain/conflux-rust.git
cd conflux-rust

# build in release mode
cargo build --release

If you are building on MacOS and get the error: could not find native static library bz2 you can try the following command:

RUSTFLAGS="-L $(brew --prefix bzip2)/lib -l bz2" cargo build

这将在**./target/release子目录中生成一个名为conflux**的可执行文件。 conflux二进制文件是一个客户端软件,我们可以用它来运行节点。

请注意,当编译一个 crate 时,如果出现错误,大多数情况下是因为您使用的 Rust 版本过旧,或者其中一些 crate 需要重新编译。 如果您使用的是Rust的最新稳定版本,清理仓库很可能解决问题,尝试:

cargo clean && cargo update

When you compiling on Linux system,By default cc is linked to gcc, you need to export the cc environment variable to point to clang

CC=clang CXX=clang++ cargo build --release

要开始运行Conflux完整节点,您可以按照运行Conflux完整节点的说明进行操作。

常见问题解答​

构建过程失败的原因是什么?​

请确保您安装了所有依赖,并且您的网络状况良好以下载rust crates。 如果您在中国,可以尝试使用rustup安装rust并设置镜像为Rust China。

主网和测试网客户端是否兼容?​

不,主网和测试网客户端不相同。

如何构建测试网客户端?​

切换到最新的测试网标签并构建源代码: 最新的测试网节点版本号为:v2.4.1-2-testnet。

git checkout <latest-released-testnet-version>  # 切换到最新测试网发布版本
cargo build --release

在哪里可以找到最新发布版本?​

您可以在Releases中找到最新发布版本。