如何在Linux上启用ccache

u59ebvdq  于 2023-02-11  发布在  Linux
关注(0)|答案(5)|浏览(133)

关于在GNU/Linux上启用ccache的文档非常少。以下是launchpad.net的回应:
目前,我认为启用ccache的最佳方法是在路径前面添加“/usr/lib/ccache”。如果您想默认为所有用户启用它,请更改/etc/environment中的PATH变量。
有人能给予我更多关于启用ccache的信息吗?

7cwmlq89

7cwmlq891#

下载最新版本的ccache以获得更好的性能。

下载后,请按照以下步骤操作:
A)使用以下命令对文件进行Tar:

$tar -xvf ccache-3.2.4.tar.bz2
 
 Note : I'm using ccache 3.2.4 Version.You can download the latest one.

B)进入ccache-3.2.4文件夹并运行以下命令:

$./configure
 $./make 
 $ sudo make install

C)转到.bashrc并插入以下内容:

export CCACHE_DIR=/home/user_name/.ccache
 export CCACHE_TEMPDIR=/home/user_name/.ccache

 Note : Fill user_name with your User Name

D)保存Bashrc并获取源代码

$ source ~/.bashrc

E)要检查ccache是否正常工作,请键入:

ccache -M 10G : To Set the ccache Size to 10GB

F)要检查ccache是否正常工作,请键入:

ccache -s : To check ccache statistics
7fhtutme

7fhtutme2#

至少有两种方法:
i)重写Makefile中的CCCXX,...标志。在R框架中,读取系统和可选用户配置文件,我只需设置

VER=4.7
CC=ccache gcc-$(VER)
CXX=ccache g++-$(VER)
SHLIB_CXXLD=g++-$(VER)
FC=ccache gfortran
F77=ccache gfortran

这也允许我在gcc版本之间来回切换。现在 * 所有 * 涉及R的编译都使用ccache
ii)对于其他用途,我已经部署了/usr/local/bin/先于/usr/bin被检查的事实。

root@max:/usr/local/bin# ls -l gcc
lrwxrwxrwx 1 root root 15 Jan 27 11:04 gcc -> /usr/bin/ccache
root@max:/usr/local/bin# ./gcc --version
gcc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

root@max:/usr/local/bin#

并且现在通过ccache调用gcc

edd@max:/tmp$ cp -vax ~/src/progs/C/benfordsLaw.c .
`/home/edd/src/progs/C/benfordsLaw.c' -> `./benfordsLaw.c'
edd@max:/tmp$ time /usr/local/bin/gcc -c benfordsLaw.c 

real    0m0.292s
user    0m0.052s
sys     0m0.012s
edd@max:/tmp$ time /usr/local/bin/gcc -c benfordsLaw.c 

real    0m0.026s
user    0m0.004s
sys     0m0.000s
edd@max:/tmp$
hrysbysz

hrysbysz3#

ccache manual有一个叫做运行模式的部分,它描述了激活ccache的官方方法,所以我建议阅读手册。
另外,正如您已经注意到的,Linux发行版经常设置一个/usr/lib/ccache目录,该目录被设计为放在PATH前面。

7fyelxc5

7fyelxc54#

如果$HOME/bin/列在$PATH/usr/bin/之前,另一种可能性(而不是Keltar所评论的export CC=ccache)是创建一个符号链接

ln -s /usr/bin/ccache $HOME/bin/gcc

那么gcc的每个execvp(3)都会找到该符号链接

qij5mzcb

qij5mzcb5#

Ubuntu安装缓存

1.sudo apt-get安装ccache
1.安装后确认安装执行**“哪个ccache”**

$ which ccache
/usr/bin/ccache

1.将以下内容添加到“~/.bashrc”或“~/.zshrc==”文件中

# ccache
export USE_CCACHE=1
export CCACHE_SLOPPINESS=file_macro,include_file_mtime,time_macros
export CCACHE_UMASK=002

**source“~/.bashrc”or"~/.zshrc”**4. ccache默认设置的5GB磁盘空间一般足够,如果担心可以增加,ccache -M 30 G5.通过版本确认安装成功

$ ccache --version
ccache version 3.4.1

Copyright (C) 2002-2007 Andrew Tridgell
Copyright (C) 2009-2018 Joel Rosdahl

1.您可以通过ccache - s查看当前配置

cache directory                     /home/username/.ccache
primary config                      /home/username/.ccache/ccache.conf
secondary config      (readonly)    /etc/ccache.conf
stats zero time                     Fri Jul 22 16:15:40 2022
cache hit (direct)                  4186
cache hit (preprocessed)             875
cache miss                          1069
cache hit rate                      82.56 %
called for link                      653
cleanups performed                     0
files in cache                      3209
cache size                          159.3 MB
max cache size                      30.0 GB

使用libzmq测试ccache

1.通过github下载libzmq的源代码

$ git clone  https://github.com/zeromq/libzmq.git
Cloning into 'libzmq'...
remote: Enumerating objects: 43791, done.
remote: Counting objects: 100% (36/36), done.
remote: Compressing objects: 100% (28/28), done.
remote: Total 43791 (delta 11), reused 24 (delta 8), pack-reused 43755
Receiving objects: 100% (43791/43791), 21.91 MiB | 1.03 MiB/s, done.
Resolving deltas: 100% (31951/31951), done.

1.在libzmq目录中创建build目录
1.修改CMakeLists. txt,添加'+'

──────┬───────────────────────────────────────────────────────────────────────────────────────
       │ File: CMakeLists.txt
───────┼──────────────────────────────────────────────────────────────────────────────────────
   1   │ # CMake build script for ZeroMQ
   2   │ project(ZeroMQ)
   3   │ 
   4   │ if(${CMAKE_SYSTEM_NAME} STREQUAL Darwin)
   5   │   cmake_minimum_required(VERSION 3.0.2)
   6   │ else()
   7   │   cmake_minimum_required(VERSION 2.8.12)
   8   │ endif()
   9   │ 
  10 + │ find_program(CCACHE_FOUND ccache)
  11 + │ if(CCACHE_FOUND)
  12 + │     set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
  13 + │     set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
  14 + │     message(STATUS "use ccache")
  15 + │ endif(CCACHE_FOUND)
  16 + │ 
  17   │ include(CheckIncludeFiles)

1.执行**“cmake.."build目录下打印并显示"-- use ccache”表示启用ccache**,但注意每个项目第一次启用ccache时并不会加快编译速度,而是将编译缓存保存到**"/home/username/. cache”**目录下,以备以后编译

$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- use ccache
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE 
...

1.使用**"/usr/bin/time”**命令记录编译时间

/usr/bin/time make -j3

result:
48.79user 14.25system 0:21.60elapsed 291%CPU (0avgtext+0avgdata 176036maxresident)k
0inputs+282248outputs (0major+2406923minor)pagefaults 0swaps

1.“rm - rf *"删除生成目录中的所有文件
1.制造..
1.使用**"/usr/bin/time”**命令记录编译时间

/usr/bin/time make -j3

result:
2.78user 2.42system 0:02.15elapsed 241%CPU (0avgtext+0avgdata 23736maxresident)k
0inputs+21744outputs (0major+232849minor)pagefaults 0swaps

https://www.cnblogs.com/jiangyibo/p/16516932.html

相关问题