Author Topic: ccache to speed up builds  (Read 22764 times)

Offline Smirftsch

  • Multiple posting newcomer
  • *
  • Posts: 22
ccache to speed up builds
« on: March 28, 2010, 12:25:33 am »
I digged a while and tried some settings, but I can't seem to be able to add ccache in CodeBlocks to speed up my builds. Where do I have to add it? Probably I'm just blind...:)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13439
    • Travis build status
Re: ccache to speed up builds
« Reply #1 on: March 28, 2010, 12:42:50 am »
Probably the easiest way is to make a bash script and replace your toolchain executable with the script ( settings -> compiler & debugger -> toolchain executable).

Create a file ccache_gcc.sh and fill it with:
Code
#!/bin/bash
ccache gcc "$@"

The in the field for C compiler type ccache_gcc.sh, do the same for C++...
Also you should change your "Compiler's installation dir and do some symbolic linking for the non ccached tools.

p.s. I've not tested the script, so it is possible that it doesn't work (I'm not a ccache user)
p.p.s. you could try to use "ccache gcc" directly, but I doubt it will work
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Smirftsch

  • Multiple posting newcomer
  • *
  • Posts: 22
Re: ccache to speed up builds
« Reply #2 on: March 28, 2010, 09:17:40 am »
No, ccache gcc doesn't work. Tried that already ;) - but I'm surprised that no one here seems to use it,even a search in the forums showed nothing really related. While it is some really important thing in my eyes, especially when comparing against vc++ it really takes way longer to recompile my project in C::B without it.

Maybe most people are just not aware about it?
http://ccache.samba.org/performance.html
just for information.

I really suggest to add such an option to use it in C::B maybe as checkbox. If testing minor changes in big projects it can safe hours of work.

PS: Thx for the idea with the script, seems to work fine ;)

Update: while it executes ccache now it doesn't seem to do its work. Maybe some path issue, so its not working yet...
« Last Edit: March 28, 2010, 12:55:25 pm by Smirftsch »

Offline reckless

  • Regular
  • ***
  • Posts: 338
Re: ccache to speed up builds
« Reply #3 on: April 03, 2010, 01:42:30 am »
#!/bin/sh
ccache gcc "$@"

works fine here :) need to tell the program youre compiling that it needs to use the wrapper.

i.e
export CC="ccache_gcc"


Offline reckless

  • Regular
  • ***
  • Posts: 338
Re: ccache to speed up builds
« Reply #4 on: April 03, 2010, 05:14:34 am »
forgot to mention dont call it ccache_gcc.sh just ccache_gcc .sh files call bash directly while scripts with #!/bin/bash
are actually handled like real executables

Offline frithjofh

  • Regular
  • ***
  • Posts: 376
Re: ccache to speed up builds
« Reply #5 on: April 03, 2010, 07:55:31 pm »
hi,

I just applied the changes to my settings and the compilation time of my rather small project went from 42 sec the first time down to 10 sec the second and every other time. great. I hope I am not mistaken, as there is no output whatsoever if or if not ccache really is taking part in the process, but from the times measured, it should be.

as I am on linux, I added a custom variable under "project build options"->"custom variables"  : CC=ccache_gcc . the script I put in /usr/bin

thanks

greetings from asturias

frithjofh
architect with some spare time  -  c::b compiled from last svn  -   openSuSE leap x86_64  -  AMD FX-4100

Offline reckless

  • Regular
  • ***
  • Posts: 338
Re: ccache to speed up builds
« Reply #6 on: April 05, 2010, 10:07:51 am »
happy it worked out :)

aye ccache can really speed things up  :D

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5403
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: ccache to speed up builds
« Reply #7 on: May 11, 2010, 02:00:57 am »
I'm interest in using it, but I found there is no simple instruction for Win32. No binaries can be found for Windows system. :(
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline reckless

  • Regular
  • ***
  • Posts: 338
Re: ccache to speed up builds
« Reply #8 on: May 11, 2010, 03:30:48 am »
on the contrary :) ftp://90.184.233.166:21/ccache.exe

mingw win32 build.

the wrapper scripts above cannot however be used on windows unless you have the msys shell in path (baaad idea) and codeblocks bitches loudly if i use bat files as wrappers  :? so have to define CC="ccache gcc" etc directly in the makefiles.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5403
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: ccache to speed up builds
« Reply #9 on: May 11, 2010, 03:39:39 am »
on the contrary :) ftp://90.184.233.166:21/ccache.exe

mingw win32 build.


Thanks, I also get a response to the author of ccache, who gives me another link in : http://ramiro.arrozcru.org/ ccache-win32-1.exe

Quote
the wrapper scripts above cannot however be used on windows unless you have the msys shell in path (baaad idea) and codeblocks bitches loudly if i use bat files as wrappers  :? so have to define CC="ccache gcc" etc directly in the makefiles.
But I'm not fully understand these sentence, seems we can only use ccache in MSYS shell. So, I can't directly used it in CodeBlocks IDE?
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline reckless

  • Regular
  • ***
  • Posts: 338
Re: ccache to speed up builds
« Reply #10 on: May 11, 2010, 03:59:26 am »
unfortunatly not atleast untill some adds the option to codeblocks :/ using a batch file as a wrapper causes codeblocks to spit out invalid compiler [YOUR ANSWER IS ALREADY THERE. SEARCH THE FORUMS!] errors but i suspect you could do it from inside the project properties by defining CC=ccache gcc to the preprocessor variables. same goes for g++ ;)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5403
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: ccache to speed up builds
« Reply #11 on: May 11, 2010, 04:53:18 am »
Sorry, I'm still confused.
As you said:
Quote
i suspect you could do it from inside the project properties by defining CC=ccache gcc to the preprocessor variables. same goes for g++

So, what's the exact steps I should do?

1, I just copy ccache.exe to the mingw/bin
2, I create a console project by Codeblocks' project wizard.
3, then, what should I do? Do I need to do some hack on the project build options?? or other modifications on project properties??? I have just add a Custom variables : CC = "ccache gcc", but it does Noting...
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline reckless

  • Regular
  • ***
  • Posts: 338
Re: ccache to speed up builds
« Reply #12 on: May 11, 2010, 03:36:12 pm »
pretty much ;) its not visible but try a larger project and notice the compile times if it works it should compile quite a lot faster :)

a way to check if its working is to show hidden files in explorer then navigate to user\your name\AppData\Roaming And look for a folder named .ccache if its there it works :).

a god project to try it out on could be codeblocks itself because of its size you should notice some better compile times. codeblocks is c++ though so the variable would be CXX="ccache g++".

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5403
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: ccache to speed up builds
« Reply #13 on: May 11, 2010, 04:54:01 pm »
I just change the Menu-settings-compiler and debugger-Tool chain executes -
I change the
C++ compiler from
Quote
mingw32-g++.exe
to
Quote
ccache.exe mingw32-g++.exe

But still can't get things to work.

With the ccache.exe from your ftp site ftp://90.184.233.166:21/ccache.exe
It works!!

Here is the build log:
Quote
-------------- Build: Debug in test_cc_cache ---------------

[ 50.0%] ccache mingw32-g++.exe -Wall -fexceptions  -g     -c C:\codeblocks_test_code\test_cc_cache\main.cpp -o obj\Debug\main.o
[100.0%] mingw32-g++.exe  -o bin\Debug\test_cc_cache.exe obj\Debug\main.o   
Output size is 1.01 MB
Process terminated with status 0 (0 minutes, 4 seconds)
0 errors, 0 warnings



with the ccache.exe from another link: http://ramiro.arrozcru.org/ ccache-win32-1.exe

I get the error log below:
Quote
-------------- Build: Debug in test_cc_cache ---------------

[ 50.0%] ccache.exe mingw32-g++.exe -Wall -fexceptions  -g     -c C:\codeblocks_test_code\test_cc_cache\main.cpp -o obj\Debug\main.o
ccache: FATAL: Unable to determine cache directory
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings
 

 :(



 
« Last Edit: May 11, 2010, 05:13:03 pm by ollydbg »
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline reckless

  • Regular
  • ***
  • Posts: 338
Re: ccache to speed up builds
« Reply #14 on: May 11, 2010, 08:54:46 pm »
yep thats the error i got if i use it in the compiler properties.

just made a test and it works ok if done like in the image.



Uploaded with ImageShack.us