"called for link" ccache 是什么意思

What does ccache mean by "called for link"

ccache 统计数据是什么意思"called for link"。我以为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

ccache确实不支持链接

它确实取代了 C 编译器(更具体地说是 C 编译器驱动程序),但是(查看它的安装和使用位置和方式)。因此,它需要 "pass through" 它收到的任何命令,而不是 handle/modify 自己到工具链的各个部分。

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

The statistics counter “called for link” is now correctly updated when linking with a single object file.

但这意味着您在一次操作中进行编译和 linking,因此 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

一步完成编译和 link(两次,以确保万无一失):

$ 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++ 总共被调用 link 4 次,其中 2 次没有源代码,只有 .o

需要预处理东西?很简单,您只是使用编译器来扩展所有 include/define 东西(例如,在寻找依赖项时)

$ 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

希望对您有所帮助!