据我所知,ccache通过捕获先前的编译并检测何时再次进行相同的编译来加快编译速度。但是,makefile做同样的事情。那么为什么我们需要ccache?我们什么时候使用它?谢谢!
我一直想知道......
ccache有一些限制吗?
如果后期编译时间的差异如此之大,为什么更多Linux开发人员不经常使用ccache?
我们的系统支持使用三种不同的工具链(gcc,icc,diab)进行构建。我不确定在这种情况下使用ccache是否安全。我的担心如下:如果我使用gcc进行构建,然后使用diab进行重建,那么在文件及其依赖项相同的情况下,是否会遇到ccache问题?
在这种情况下,我不希望受到打击,因为我希望使用diab重新编译文件。
我的项目有时会受益于ccache,所以我一直在使用ccache.我现在正在添加预编译头文件.一些消息来源表明,这两者是不相容的,必须在它们之间做出选择.但我在ccache的文档中发现它在某种程度上支持PCH:https: //ccache.samba.org/manual.html#_precompiled_headers
实际上,当我尝试使用ccache在使用Clang -include-pch选项的同时构建.o文件时,我发现ccache正在成功缓存.o.第一次编译尝试需要1.5秒,第二次只需0.05秒(因为ccache完成了它的工作).
麻烦的是,如果我用clang++而不是with 运行相同的编译命令/usr/lib/ccache/clang++,则需要0.5秒......除非我离开-include-pch部分,在这种情况下需要大约1.5秒.似乎ccache可能会导致我的PCH被忽略,或者其他什么.
我按照说明(从上面的链接).正如那里指出的那样,我的ccache.conf看起来像这样:
sloppiness=pch_defines,time_macros
Run Code Online (Sandbox Code Playgroud)
我已经试过的一切合理的组合#include,-include,-include-pch和-fpch-preprocess我能想到的.编译总是花费1.5秒然后0.05秒,当它应该花费0.5秒,然后0.05秒.
有可能做到这一点,或者我必须在ccache和PCH之间做出选择吗?
我正在将gcc 4.9.2与ccache 3.1.10一起使用。我的shell环境包含GCC_COLORS=auto(从这里,尝试yes和always太)。
作为最低限度的测试,我编译了该main.c文件
int main() {
int a;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
与gcc -c main.c -Wall -o main.o并观察(根据需要)
main.c: In function ‘main’:
main.c:2:7: warning: unused variable ‘a’ [-Wunused-variable]
int a;
^
Run Code Online (Sandbox Code Playgroud)
有main.c:和main.c:2:7:,‘main’:和‘a’粗体的^黑体字绿色,warning:品红色粗体。
与编译ccache的colorisation消失。
注意:ccache gcc -Wall -c main.c -o main.o无色,但ccache gcc -Wall main.c -o main仍保持彩色。
NB2:ccache gcc -Wall -c …
我运行一个CI服务器,用于构建自定义Linux内核.CI服务器功能不强,每个构建的时间限制为3h.为了在这个限制内工作,我有了使用ccache缓存内核构建的想法.我希望我可以在每个次要版本发布时创建一个缓存,并将其重新用于补丁版本,例如我有一个我为4.18制作的缓存,我想用于所有4.18.x内核.
删除构建时间戳后,这适用于我正在构建的确切内核版本.对于上面引用的4.18内核,在CI上构建它会提供以下统计信息:
$ ccache -s
cache directory
primary config
secondary config (readonly) /etc/ccache.conf
stats zero time Thu Aug 16 14:36:22 2018
cache hit (direct) 17812
cache hit (preprocessed) 38
cache miss 0
cache hit rate 100.00 %
called for link 3
called for preprocessing 29039
unsupported code directive 4
no input file 2207
cleanups performed 0
files in cache 53652
cache size 1.4 GB
max cache size 5.0 GB
Run Code Online (Sandbox Code Playgroud)
缓存命中率100%和一小时完成构建,梦幻般的统计数据和预期.
不幸的是,当我尝试构建4.18.1时,我得到了
cache directory
primary config
secondary config (readonly) /etc/ccache.conf
stats …Run Code Online (Sandbox Code Playgroud) 在我们的 C++ 项目中,我们设法设置GitHub Actions,使用ccache构建我们的源代码。
它在 Linux 上运行得很好,多亏了ccache,构建在不到 5 分钟内就成功了。
不幸的是,当尝试在 macOS 上构建时,ccache似乎不起作用,给出:
cache directory /Users/runner/.ccache
primary config /Users/runner/.ccache/ccache.conf
secondary config (readonly) /usr/local/Cellar/ccache/3.7.11_1/etc/ccache.conf
stats updated Sun Aug 23 11:57:31 2020
cache hit (direct) 0
cache hit (preprocessed) 0
cache miss 7175
cache hit rate 0.00 %
cache file missing 1
cleanups performed 2976
files in cache 165
cache size 422.4 MB
max cache size 500.0 MB
Run Code Online (Sandbox Code Playgroud)
因此,macOS 构建大约需要 40 分钟才能完成。
构建示例: https: …
我正试图在Windows上的Qt Creator中设置ccache.
不幸的是,我找不到任何好的指示.如何让它工作?
我在Cygwin上安装了ccache.
编辑:
我试过添加
QMAKE_CXX+="ccache g++"
Run Code Online (Sandbox Code Playgroud)
作为qmake构建步骤中的附加参数.
但是在编译输出中,我仍然有"g ++ -c -g -Wall ...",我想它应该是"ccache g ++ ..."
我正在尝试在 Xcode 中使用 Address Sanitizer,但我也使用 ccache 来加速我的构建。为此,我CC在 Xcode 项目级别设置了标志以指向我存储在的脚本~/projects/support/cmake/ccache-clang。脚本如下:
#!/bin/sh
if type -p /usr/local/bin/ccache >/dev/null 2>&1; then
export CCACHE_CPP2=true
exec /usr/local/bin/ccache "${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" "$@"
else
exec "${DEVELOPER_DIR}/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" "$@"
fi
Run Code Online (Sandbox Code Playgroud)
这样就达到了预期的效果(如果开发系统上安装了ccache,则使用ccache)。这运作良好。
现在,当我们为给定方案打开地址消毒器时,问题就出现了。构建成功完成,但是当我们尝试运行时,我们终于看到了这个错误:
Error: Check dependencies
Could not determine version of clang to find its Address Sanitizer library: ~/projects/support/cmake/ccache-clang
Run Code Online (Sandbox Code Playgroud)
也许这是由于 Xcode 中的一些 hacky 实现导致的,它试图解析编译器的路径以确定版本?
想知道如何修改我的脚本以允许 Address Sanitizer 工作。CC当前的解决方法是当我们需要进行消毒工作时删除覆盖的标志。
使用 Xcode 8.3.1
所以用这个人为的代码 - 用 clang 编译工作得很好,但是当使用 ccache 时会出现额外的警告/错误 - 我认为 ccache 应该透明地传递这些。这是来自 epel 存储库的 CentOS 6 上的 ccache 3.1.6 - 升级不是一种选择,因为这是生产环境。
#include <byteswap.h>
int main()
{
int i = 42;
auto j = bswap_32(i);
(void)j;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
因此,带有未使用的包含路径的示例 1 没有给出错误:
clang++ -Wno-c++98-compat -Wall -Werror -std=c++17 -I/usr/local/include -c ccache.cpp
Run Code Online (Sandbox Code Playgroud)
但是使用 ccache 我得到:
ccache clang++ -Wno-c++98-compat -Wall -Werror -std=c++17 -I/usr/include/xmlib -c ccache.cpp
clang-5.0: error: argument unused during compilation: '-I /usr/include/xmlib' [-Werror,-Wunused-command-line-argument]
Run Code Online (Sandbox Code Playgroud)
没有额外包含的示例 2 工作得很好:
clang++ -Wno-c++98-compat -Wall -Werror -std=c++17 -c ccache.cpp
Run Code Online (Sandbox Code Playgroud)
并使用 …
ccache ×10
c++ ×3
gcc ×2
azerothcore ×1
clang++ ×1
gcc-warning ×1
icc ×1
linux ×1
linux-kernel ×1
macos ×1
qt ×1
qt-creator ×1
xcode ×1
xcode8 ×1