- Author:Echo Chen(陈斌)
- Email:chenb19870707@gmail.com
- Blog:Blog.csdn.net/chen19870707
- Date:May 9th, 2013
Explain
在做游戏服务器时,由于耦合度较高,每次编译都需要编译整个工程,非常耗时,偶然的发现了ccache,安装使用了一下,果然神奇,原来需要5分钟编译的工程1分钟可以编译完成,很好用,下面mark一下ubuntu下安装使用方法。
- 安装ccache
sudo apt-get install ccache- 查看ccache 安装位置
whereis ccache查看安装路径, /usr/bin/ccache
- 创建gcc,g++链接
mkdir ~/.bin
cd ~/.bin/
ln -s /usr/bin/ccache gcc
ln -s /usr/bin/ccache g++- PATH设置,更改本地.bashrc文件,修改gcc,g++链接到ccache
vim ~/.bashrc添加 export PATH="/home/<user>/.bin:$PAHT- 确认是否生效
which g++
which g++如果是/home/<user>/.bin/g++就成功了;
直接编译项目,是不是飞一样的感觉,
xcode ccache加速:https://stackedit.io/viewer#!provider=gist&gistId=bace97f64151a503b824&filename=speedup-xcode-via-ccache-zhzheng-1.md
此外ccache也支持android(MacOS)
- 安装Homebrew Google之
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
brew update
brew install ccachebrew 会把ccache安装到/usr/local/bin,确保这个路径在你的$PATH中
- 设置ccache缓存大小,最好超过10G
ccache -M 200G
ccache -s我设置了缓存空间200G,对build-machine应该足够了。ccache -s可以查看ccache的运行状态
- 增加CCACHE变量 修改.bashrc or .bash_profile
export NDK_CCACHE=ccache
export USE_CCACHE=1- 修改build_native.sh. 将其中的ndk-build -j3…改为 ndk-build -j16
- 四核cpu配置8,16,32都可以,看自己习惯
- 注意下面代码中的 -j16
# run ndk-build
if [[ "$buildexternalsfromsource" ]]; then
echo "Building external dependencies from source"
"$NDK_ROOT"/ndk-build -j16 -C "$APP_ANDROID_ROOT" $* \
"NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/source"
else
echo "Using prebuilt externals"
"$NDK_ROOT"/ndk-build -j16 -C "$APP_ANDROID_ROOT" $* \
"NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt"下面内容可以忽略
如果不想修改native_build.sh,也可以通过修改ndk-build工具达到强制gcc并行编译的数量。操作步奏如下
- 创建ndk-build-j16脚本,内容在后面
- ndk-build-j16 我放到了~/bin中,也可以直接放到$NDK_ROOT/中
- chmod +x ~/bin/ndk-build-j16, only once
- ln -s $HOME/bin/ndk-build-j16 $NDK_ROOT/bin/ndk-build-j16
- mv -v $NDK_ROOT/ndk-build ndk-build.orig
- ln -s $NDK_ROOT/ndk-build-j16 $NDK_ROOT/ndk-build
~/bin/ndk-build-16 的文件内容,记得chmod +x
#!/bin/bash
# ndk-build wrapper, for ignore -jN options
# this file should put into $NDK_ROOT
# mv -v $NDK_ROOT/ndk-build ndk-build.orig
# ln -s $NDK_ROOT/ndk-build-j16 $NDK_ROOT/ndk-build
# ndk-build-j16 is current script name
options=() # the buffer array for the parameters
eoo=0 # end of options reached
NDKBUILD_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
while [[ $1 ]]
do
if ! ((eoo)); then
case "$1" in
-j[0-9]+)
shift
;;
--)
eoo=1
options+=("$1")
shift
;;
*)
options+=("$1")
shift
;;
esac
else
options+=("$1")
# Another (worse) way of doing the same thing:
# options=("${options[@]}" "$1")
shift
fi
done
$NDKBUILD_DIR/ndk-build.orig -j16 "${options[@]}"版权声明:本文为chen19870707原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。