The compilation environment in Ubuntu 20.04 LTS source is GCC 9, but the latest version of GCC is already 10. But there is no easy way to install the latest version of GCC 10.

It just so happens that LLVM also released version 10. The speed of clang compilation is much faster than gcc, and the generated binary volume is smaller.

Since GCC 10 cannot be installed, install LLVM 10. The official one-click installation script is provided. For the specific installation process, please refer to here: https://apt.llvm.org

After installation, you only need to set the following three environment variables to use clang by default:

export CC=/usr/bin/clang-10
export CPP=/usr/bin/clang-cpp-10
export CXX=/usr/bin/clang++-10
export LD=/usr/bin/ld.lld-10

Description of environment variables:

  • CC : C compilerclang
  • CPP : C precompiled processorclang-cpp
  • CXX : C++ compilerclang++
  • LD : Linkerld.lld