distcc 可以用来联合编译 linux 下代码
github: https://github.com/distcc/distcc
编译机安装 distcc 服务器
开发机安装 distcc 客户端
下面介绍安装过程
2 种方式,直接 yum 或者编译安装
yum 安装
yum install -y distcc-server
是 2019 年的版本
编译安装
#!/bin/bash
set -ex
yum install binutils-devel python3-devel -y
git clone https://github.com/distcc/distcc.git
pushd distcc
./autogen.sh
./configure
make
make install
popd
可以获取最新版本
启动 distccd 服务
类似以下命令:
#!/bin/bash
set -ex
yum install -y centos-release-scl
yum install -y devtoolset-7-gcc devtoolset-7-gcc-c++
if [ ! -f /etc/systemd/system/distccd.service ]; then
cat >/etc/systemd/system/distccd.service <<EOF
[Unit]
Description=Distccd A Distributed Compilation Server
After=network.target
[Service]
User=nobody
EnvironmentFile=-/etc/sysconfig/distccd
ExecStart=/usr/local/bin/distccd --no-detach --daemon \$OPTIONS
[Install]
WantedBy=multi-user.target
EOF
ln -s /etc/systemd/system/distccd.service /etc/systemd/system/multi-user.target.wants/distccd.service
fi
cat >/etc/distcc/cmdlist.config <<EOF
cc
gcc
g++
c++
EOF
cat > /etc/sysconfig/distccd << EOF
OPTIONS="--user nobody --allow 0.0.0.0/0 --port 1234 --nice 20 --verbose --log-file /tmp/distccd.log"
DISTCC_CMDLIST="/etc/distcc/cmdlist.config"
DISTCC_CMDLIST_NUMWORDS="4"
PATH="/opt/rh/devtoolset-7/root/usr/bin/"
EOF
mkdir -p /usr/local/lib/distcc
systemctl daemon-reload
systemctl restart distccd.service
systemctl link distccd.service
systemctl enable distccd.service
说明:
类似以下命令:
yum install -y distcc
cat >> ~/.bashrc << EOF
export DISTCC_VERBOSE=1
export DISTCC_LOG="/tmp/distcc.log"
export DISTCC_HOSTS="172.26.144.20:1234 172.26.144.21:1234"
EOF
注意 DISTCC_HOSTS 不要用主机名、域名。见 https://github.com/distcc/distcc/issues/293
SET(CMAKE_C_COMPILER distcc)
SET(CMAKE_CXX_COMPILER distcc)
以上