在項目的開發過程中,經常出現多個開發人員集中在某個 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秒更新一次。