Chinaunix首页 | 论坛 | 博客
  • 博客访问: 239247
  • 博文数量: 47
  • 博客积分: 1229
  • 博客等级: 中尉
  • 技术积分: 568
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-20 10:06
文章分类

全部博文(47)

文章存档

2014年(1)

2013年(7)

2012年(1)

2011年(38)

分类: LINUX

2011-01-28 10:31:44

   如果你经常编译大型的C/C++工程,不使用ccache你就out了。

   cache is a compiler cache. It speeds up recompilation by caching previous compilations and detecting when the same compilation is being done again. Supported languages are C, C++, Objective-C and Objective-C++.


Usage

使用ccache
  • 编译指令前增加ccache. $ ccache gcc xxx
  • 创建软链接。 $ ln -s ccache /usr/local/bin/gcc

建议使用第一种方式,因为ccache偶尔也犯晕,当由于它出现错误的时候, 很难看出端倪。曾在某次编译某份代码时,ccache对某个编译选项的判断失误导致编译失败,死活查不出来为什么原因。所以当出现某些怪异的现象时,请用正常的方式编译试试。


Example
  • 编译软件包
  1. [/tmp/bash-4.1 0]$ uname -a
  2. Linux AP 2.6.37-gentoo #1 SMP PREEMPT Sun Jan 16 14:55:15 CST 2011 i686 Intel(R) Core(TM)2 Duo CPU T8100 @ 2.10GHz GenuineIntel GNU/Linux
  3. [/tmp/bash-4.1 0]$ CC="ccache gcc" ./configure
  4. [/tmp/bash-4.1 0]$ time make
  5. real 0m47.343s
  6. user 0m39.572s
  7. sys 0m3.244s
  8. [/tmp/bash-4.1 0]$ make clean
  9. [/tmp/bash-4.1 0]$ time make
  10. real 0m10.131s
  11. user 0m5.597s
  12. sys 0m1.077s

由上可以看出,使用ccache后, 编译速度快了5倍(中间很长一段时间不是gcc在编译,否则更快)。Wonderful..


  • 编译内核
  1. [/tmp/linux-2.6.34 0]$ uname -a
  2. Linux boeye-AP 2.6.37-gentoo #1 SMP PREEMPT Wed Jan 12 20:06:14 CST 2011 x86_64 AMD Athlon(tm) II X4 630 Processor AuthenticAMD GNU/Linux
  3. [/tmp/linux-2.6.34 0]$ grep "make" build
  4. 28:make -j4 ARCH=arm CROSS_COMPILE="ccache arm-linux-" O=$outdir $@
  5. [/tmp/linux-2.6.34 0]$ time ./build
  6. real 3m4.146s
  7. user 10m30.640s
  8. sys 0m37.138s
  9. [/tmp/linux-2.6.34 0]$ ./build clean
  10. [/tmp/linux-2.6.34 0]$ time ./build
  11. real 0m23.714s
  12. user 0m31.603s
  13. sys 0m12.777s

在交叉编译内核时,编译速度也快了近9倍。


  • 编译Android

Android中,使用ccache,只需要添加环境变量'$ export USE_CCACHE=1', 不同的是,默认它不用HOST的ccache程式,而使用自带的ccache. 编译android需要较大的缓冲区:

  1. $ ccache -M 3G    // 将缓冲区设置为3G


Conclude

看过以上三个例子,如果你仍没有使用ccache的欲望,欢迎告诉我理由:)

阅读(6521) | 评论(0) | 转发(1) |
0

上一篇:bash 目录快速回退

下一篇:小小的抱怨~

给主人留下些什么吧!~~