Centos install distcc+ccache to speed up c/c++ compilation

distcc is a distributed C/C++ compilation tool, ccache will cache compilation information, the combination of the two will greatly increase the compilation speed.
0. Install gcc, g++ and python environment before installation, and install the Binutils toolkit.

yum install -y gcc
yum install -y gcc-c++
yum install -y python36
yum install -y python3-devel
yum install -y binutils-devel

Then go to https://distcc.github.io/ to download distcc, recommend a new version
https://github.com/distcc/distcc/releases/download/v3.3.3/distcc-3.3.3.tar.gz

  1. Install distcc
#解压 
tar -xvf distcc-3.3.3.tar.gz
#安装
cd distcc-3.3.3 
./configure && make && sudo make install
  1. Install ccache, get it with one command
yum install -y ccache
  1. Configuration
    Assuming that distcc is to be deployed on three machines, they are respectively
    192.168.1.2
    192.168.1.3
    192.168.1.4,
    then you must first perform steps 0, 1, and 2 on these three machines .
    Then edit .bashrc (vim ~/.bashrc) and add the following at the end
export DISTCC_HOSTS="192.168.1.2 192.168.1.3 192.168.1.4"
export DISTCC_POTENTIAL_HOSTS="192.168.1.2 192.168.1.3 192.168.1.4"
export DISTCC_LOG="./distcc_runtime.log"

Don't forget to source ~/.bashrc to make the configuration take effect, otherwise it will only take effect when you log in to the session next time.

  1. Run distccd

distccd --daemon --allow 192.168.1.2/8 --user nobody --enable-tcp-insecure
check it

[root@localhost ~]# ps -ef|grep distcc
nobody   21779     1  0 Dec18 ?        00:00:00 distccd --daemon --allow 192.168.1.2/8 --user nobody --enable-tcp-insecure
nobody   21780 21779  0 Dec18 ?        00:00:00 distccd --daemon --allow 192.168.1.2/8 --user nobody --enable-tcp-insecure
nobody   21781 21779  0 Dec18 ?        00:00:00 distccd --daemon --allow 192.168.1.2/8 --user nobody --enable-tcp-insecure
nobody   21782 21779  0 Dec18 ?        00:00:00 distccd --daemon --allow 192.168.1.2/8 --user nobody --enable-tcp-insecure
nobody   21785 21779  0 Dec18 ?        00:00:00 distccd --daemon --allow 192.168.1.2/8 --user nobody --enable-tcp-insecure
  1. Client configuration and operation, mainly the two environment variables of CC and CXX
    When using cmake,
CC="distcc ccache cc" CXX="distcc ccache g++" cmake ..

Or add
export CXX="distcc ccache g++" in the user configuration file as in step 3

I tested it with a small project. After using distcc+ccache, the compilation time was reduced from five minutes to one minute, which was very cool. In addition, when compiling, you can view the distributed compilation status through distccmon-text n on the client side, (n represents refreshing every n seconds), you can see that different source code files will be compiled on different machines, thereby improving efficiency.
diatcc+ccache is simple to get started, convenient and easy to use, to a certain extent alleviate the problem of long time-consuming C/C++ compilation.

Guess you like

Origin blog.csdn.net/niu91/article/details/111491038