ccache“被称为链接”是什么意思

Bri*_*ray 4 c caching ccache

什么是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
Run Code Online (Sandbox Code Playgroud)

mfr*_*fro 5

ccache 确实不支持链接。

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


小智 5

我也不太清楚阅读发行说明

现在,与单个目标文件链接时,“需要链接”的统计信息计数器已正确更新。

但这意味着您要在单个操作中进行编译和链接,因此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
Run Code Online (Sandbox Code Playgroud)

一步即可进行编译和链接(请确保两次):

$ 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
Run Code Online (Sandbox Code Playgroud)

什么都没有缓存,因为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
Run Code Online (Sandbox Code Playgroud)

现在工作了:

  • 第一次编译使高速缓存未命中,并存储了结果(两个文件:清单加.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
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助 !