distcc 的使用

在项目的开发过程中,经常出现多个开发人员集中在某个 linux 内网开发机上统一开发的情况,随着开发人员越来越多、项目编译得越来越频繁,开发机的压力越来越大,所以考虑用代码交叉编译的方式来缓解开发机的压力。

distcc 的概述:在需要使用 distcc 的服务器上,安装 distcc 软件。

(1)要把某台机子当成配合编译的机器,需要在这台机子上启动 distcc 服务;

(2)当在一台机子上需要其他机子交叉编译,则这台机子需要配置其他机子的信息,将其他机子的 ip 加到这个环境变量里面 DISTCC_POTENTIAL_HOSTS。

distcc 的安装:

1、首先根据官网安装 https://distcc.github.io/


      ./autogen.sh              # If "configure" does not already exist.
      ./configure
      make
      make check                # Optional! Should have python >= 3.1 installed.
      make install              # You may need to use "sudo" for this command.
      make installcheck         # Optional! Should have python >= 3.1 installed.
      update-distcc-symlinks    # Needs "sudo". Run this again if you install/remove compilers

2、./configure 的时候报错:configure: error: Cannot find libiberty。这是因为缺少 libbinutils 库,则安装 binutils-devel。

3、make 的时候发现 make 不成功,make 暂停在:


if test -z ":"; then   
  echo "Not building include-server: No suitable python found";
else                                           
  mkdir -p "./_include_server" &&     
  DISTCC_VERSION="3.3.2"                       
  SRCDIR="."                           
  CFLAGS="-g -O2 -MD -W -Wall -Wimplicit -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Wmissing-declarations -Wuninitialized -pthread -Wp,-U_FORTIFY_SOURCE -Wno-missing-prototypes -Wno-missing-declarations -Wno-write-strings"          
  CPPFLAGS="-DMINILZO_HAVE_CONFIG_H -DHAVE_CONFIG_H -D_GNU_SOURCE -DLIBDIR=""/usr/local/lib"" -DSYSCONFDIR=""/usr/local/etc"" -DPKGDATADIR=""/usr/local/share/distcc"" -Isrc -I"./src" -I"./lzo" -I"./popt""                       
  : "./include_server/setup.py"
      build                                    
        --build-base="./_include_server" 
        --build-temp="./_include_server";
fi

根据官网 https://raw.githubusercontent.com/distcc/distcc/master/INSTALL 说明,python 版本需要大于 3.1。

4、在服务器上安装 python3.4,只要 /user/bin/ 目录下有 python3.4 就可以了,python 默认安装在 /usr/local 下,可以 ./configure --prefix=/usr。python 安装成功以后,要重新运行下 distcc 的 ./configure ,再 make。

5、ln -s /usr/lib/distcc/ /usr/local/lib/distcc

distcc 的配置

1、用于交叉编译的机器,需要运行 distcc 的服务,一般用以下命令:

distccd --user nobody --daemon --allow 127.0.0.1 --allow 192.168.2.0/24

2、需要使用交叉编译的服务一般在编译脚本里加上以下命令:

  export DISTCC_HOSTS="localhost 192.168.2.236 192.168.2.238"

  export DISTCC_POTENTIAL_HOSTS="localhost 192.168.2.236 192.168.2.238"

  export DISTCC_LOG="./distcc.log" #编译日志

3、如果是使用 cmake,可以使用以下命令:

  cmake -DCMAKE_C_COMPILER=/usr/lib/distcc/cc -DCMAKE_CXX_COMPILER=/usr/lib/distcc/g++ ../

需要确认哪些文件是在哪些服务器上编译的,可以使用命令 distccmon-text 1,1表示1秒更新一次。

原文地址:https://www.cnblogs.com/ljm0/p/11224726.html