ccache 的“要求链接”是啥意思

Posted

技术标签:

【中文标题】ccache 的“要求链接”是啥意思【英文标题】:What does ccache mean by "called for link"ccache 的“要求链接”是什么意思 【发布时间】:2015-04-23 15:48:36 【问题描述】:

ccache 统计“调用链接”是什么意思。我以为 ccache 只包装了编译器,而不是链接器?

[Brian@localhost ~]$ ccache -s
cache directory                     /home/Brian/.ccache
cache hit (direct)                 19813
cache hit (preprocessed)              67
cache miss                            11
called for link                      498
called for preprocessing              10
unsupported source language          472
no input file                         12
files in cache                    258568
cache size                          33.8 Gbytes
max cache size                     100.0 Gbytes

【问题讨论】:

【参考方案1】:

ccache确实不支持链接。

它确实取代了 C 编译器(更具体地说,是 C 编译器驱动程序)(查看它的安装和使用位置和方式)。因此,它需要“传递”它接收到的任何命令,而不是处理/修改自己到工具链的各个部分。

【讨论】:

【参考方案2】:

阅读release notes 我也不是很清楚:

统计计数器“调用链接”现在可以正确更新 与单个目标文件链接。

但这意味着您在单个操作中进行编译和链接,因此 ccache 无法透明地提供结果。

带有基本 hello.c 程序的演示。首先让我们清除所有内容:

$ ccache -Czs
Cleared cache
Statistics cleared
cache directory                     /home/jdg/.ccache
cache hit (direct)                     0
cache hit (preprocessed)               0
cache miss                             0
files in cache                         0

一步完成编译和链接(两次,只是为了确定):

$ ccache g++ hello.c
$ ccache g++ hello.c
$ ccache -s
cache hit (direct)                     0
cache hit (preprocessed)               0
cache miss                             0
called for link                        2
files in cache                         0

没有缓存,因为 ccache 就是不能

分两个单独的步骤(也是两次):

$ ccache g++ -c hello.c ; g++ hello.o
$ ccache g++ -c hello.c ; g++ hello.o
$ ccache -s
cache hit (direct)                     1
cache hit (preprocessed)               0
cache miss                             1
called for link                        4
no input file                          2
files in cache                         2

现在成功了:

第一次编译发生了缓存未命中,并存储了结果(两个 文件:清单加 .o) 第二次缓存命中 g++ 总共被调用了 4 次链接,包括 2 次没有源但只有 .o

需要预处理的东西?很简单,您只需使用编译器来扩展所有包含/定义的内容(例如,在查找依赖项时)

$ g++ -E hello.c
$ g++ -M hello.c
$ ccache -s
cache hit (direct)                     1
cache hit (preprocessed)               0
cache miss                             1
called for link                        4
called for preprocessing               2
unsupported compiler option            1
no input file                          2
files in cache                         2

希望这会有所帮助!

【讨论】:

您是否故意在 分两步执行 部分中运行 g++ 而没有 ccache

以上是关于ccache 的“要求链接”是啥意思的主要内容,如果未能解决你的问题,请参考以下文章

ccache 在不删除 CMake 文件的情况下不会命中缓存

iOS编译加速-CCache

Makefile“重新链接”是啥意思? [关闭]

这个链接是啥意思? [关闭]

href链接中的“/./”是啥意思?

链接URL是啥意思