Building Starcoin from source
- Clone the source code to local
git clone https://github.com/starcoinorg/starcoin.git
- Setup build environment
- 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
(2) Build the release version
cargo build --release
- Target file
After compiling, you can find the corresponding starcoin program in the target directory.
- The debug version is in the
- The release version is in the
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.
Set the value of
LIBCLANG_PATH to the
bin directory of LLVM compilation tool set.
Set according to your specific installation location, for example:
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.
- Open Windows Explorer, type
%UserProfile%in the address bar and hit enter.
- Create a file in this directory named
- 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)
wsl --shutdownin cmd to close WSL2, and then reopen it.
Why do I compile for so long?
This situation usually occurs on users with low computer configuration. Here are two feasible suggestions:
Upgrade computer configuration.
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.
cargo build -j 1
For specific test cases, see the discussion in [bug] Excessive swap may result in slower builds #70.
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
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
- To install gcc on Ubuntu, simply run,
build-essentialcontains 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
- If the error message
Could not find directory of OpenSSL installationappears, 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
git config --global http.https://github.com.proxy [protocol://][user[:password]@]proxyhost[:port]