如何有选择地使用ccache?

时间:2010-04-22 16:28:22

标签: linux gcc ccache

我必须编译用C ++编写的应用程序的多个版本,我认为使用ccache来加速这个过程。

ccache howtos有一些示例建议创建名为gcc,g ++等的符号链接,并确保它们在原始gcc二进制文件之前出现在PATH中,因此使用ccache。

到目前为止一直很好,但我只想在编译这个特定的应用程序时使用ccache,而不是总是这样。

当然,我可以编写一个shell脚本,每次我想编译应用程序时都会尝试创建这些符号链接,并在编译应用程序时删除它们。但这看起来像文件系统滥用给我。

有没有更好的方法有选择地使用ccache,而不是总是?

为了编译单个源代码文件,我可以手动调用ccache而不是gcc并完成,但我必须处理一个复杂的应用程序,该应用程序使用自动构建系统来存储多个源代码文件。

4 个答案:

答案 0 :(得分:18)

仅绕过ccache:

export CCACHE_DISABLE=1

欲了解更多信息:

man ccache

...

        If you set the environment variable CCACHE_DISABLE then ccache will just call the real
       compiler, bypassing the cache completely.

...

答案 1 :(得分:3)

什么操作系统? Linux呢?大多数打包版本的ccache已经将这些符号链接放入一个目录中,例如在我们的Fedora机器上,它们位于/ usr / lib64 / ccache中。

所以你可以做到

PATH=/usr/lib64/ccache:${PATH} make

当你想用ccache构建时。

大多数软件包还在/etc/profile.d/中安装了一个文件,它通过将ccache添加到PATH来自动启用ccache,如上所述。

如果您的系统出现这种情况,只需在您的环境中设置CCACHE_DISABLE=1(请参阅man ccache以获取更多信息)以禁用ccache - ccache仍将运行,但只会调用真正的编译器。

答案 2 :(得分:2)

创建符号链接的替代方法是显式使用ccache gcc作为C编译器,ccache g++作为C ++编译器。例如,如果Makefile使用变量CCCXX来指定编译器,则可以使用make CC="ccache gcc" CXX="ccache g++"进行构建,或者在配置时(./configure CC="ccache gcc" CXX="ccache g++")进行设置。 / p>

答案 3 :(得分:1)

我无数次偶然发现了这个。对我来说,最好的解决方案是这样做:

export CCACHE_RECACHE=1;

从ccache手册页:

Corrupt object files
   It should be noted that ccache is susceptible to general storage problems. If a bad object file sneaks into
   the cache for some reason, it will of course stay bad. Some possible reasons for erroneous object files are
   bad hardware (disk drive, disk controller, memory, etc), buggy drivers or file systems, a bad prefix_command
   or compiler wrapper. If this happens, the easiest way of fixing it is this:

    1. Build so that the bad object file ends up in the build tree.

    2. Remove the bad object file from the build tree.

    3. Rebuild with CCACHE_RECACHE set.