Skip to main content

Building Starcoin from source

Quick start

  1. Clone the source code to local
git clone https://github.com/starcoinorg/starcoin.git
cd starcoin
  1. Setup build environment
./scripts/dev_setup.sh
  1. Buid with Cargo

Note: Two versions (debug, release) of build methods are provided here, the debug version is used in the development environment, and the release version is used in the production environment.

If you want to use it formally, use the release version, there is an order of magnitude difference in performance between the debug version and the release version.

(1) Build the debug version

cargo build

(2) Build the release version

cargo build --release
  1. Target file

After compiling, you can find the corresponding starcoin program in the target directory.

  • The debug version is in the target/debug/starcoin directory
  • The release version is in the target/release/starcoin directoryg

Troubleshooting

Windows

If the following error information appears during the compilation process in Windows:

'Unable to find libclang: "couldn't find any valid shared libraries matching: ['clang.dll', 'libclang.dll'], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: [])"'

This is because the LIBCLANG_PATH environment variable is not set.

Solution:

Set the value of LIBCLANG_PATH to the bin directory of LLVM compilation tool set.

Set according to your specific installation location, for example:

C:\Program Files\LLVM\bin

WSL

Q1:

Compiling with WSL2 may give the following error message:

error: linking with `cc` failed: exit status: 1

This is because the swap memory of WSL2 is not set, or is less than the maximum memory of WSL2.

Solution:

  • Open Windows Explorer, type %UserProfile% in the address bar and hit enter.
  • Create a file in this directory named .wslconfig
  • An example of the written content is as follows: (according to the actual allocation of your computer, make sure that swap is greater than or equal to memory)
    [wsl2]
    memory=2GB
    swap=4GB
  • Execute wsl --shutdown in cmd to close WSL2, and then reopen it.

Q2:

Why do I compile for so long?

This situation usually occurs on users with low computer configuration. Here are two feasible suggestions:

  1. Upgrade computer configuration.

  2. Controls the number of jobs Cargo compiles with.

For low-profile machines, controlling the number of cores is the key to greatly improving compilation efficiency.

For example:

cargo build -j 1

For specific test cases, see the discussion in [bug] Excessive swap may result in slower builds #70.

CentOS

If your operating system is CentOS 6.x, then use such commands to install some toolsets.

yum install centos-release-scl
yum install devtoolset-7
. /opt/rh/devtoolset-7/enable

Common troubleshooting

Q1:

The following error message appears when compiling with Cargo:

error: linker cc not found | = note: No such file or directory (os error 2)

This is because Cargo cannot find the cc compiler program (linker) to compile the given application.

Since Rust does not yet include its own linker, usually we need to install a C compiler, such as: compilation tools such as gcc and cmake.

Solution:

  • To install gcc on Ubuntu, simply run, build-essential contains the basic toolset needed to compile and develop:
sudo apt install build-essential
  • To install Cmake on Arch Linux, enable the [Extra] repository and run:
sudo pacman -S gcc cmake
  • On Fedora, RHEL, CentOS:
sudo dnf install gcc cmake

Q2:

  • If the error message Could not find directory of OpenSSL installation appears, you need to install the OpenSSL library.
  • If the error Unable to find libclang: "the `libclang` shared library at /usr/lib64/clang-private/libclang.so.6.0" appears, it may be the cause of llvm-private. The solution is to uninstall it:
    rpm qa | grep "llvm-private" # Find packages containing llvm-private
    rpm -e --nodeps llvm-private-6.0.1-2.el7.x86_64 # Uninstall found packages
  • After each compilation error, after solving, you need to cargo clean, remove the previously compiled object files, and then recompile.

GitHub network issue

If the following error message shows up at start of building:

error: failed to get `xxx` as a dependency of package `...`
...
...
fatal: couldn't find remote ref HEAD

You may need to set up a proxy server for GitHub:

git config --global http.https://github.com.proxy [protocol://][user[:password]@]proxyhost[:port]