0

I have a c++ project with many files. When I build the project making even small changes to the code, It recompiles a large no of files. This is increasing the compile time of the project. So I need suggestion about the ways I can improve the structure of the project or any other optimisations possible which will help in reducing the compile time of the project. Also there are a couple of files which are getting recompiled even when I make no changes to the project. Somehow make doesn't detect that those files need not be recompiled or may be I am missing something.

I am using Codelite on linux(Ubuntu) for my project. The language is C++.

Kriateive
  • 108
  • 1
  • 9
  • 1
    I don't think it has to do anything with codelite. Check http://stackoverflow.com/questions/318398/why-does-c-compilation-take-so-long and http://stackoverflow.com/questions/373142/what-techniques-can-be-used-to-speed-up-c-compilation-times – abnvp Jan 03 '13 at 05:21
  • Even if there is no problem with codelite, Are there ways to reduce the no of files recompiled? One way for example is to use forward declarations. Currently even if I make no changes some files get recompiled. why? Are there other techniques used (like Forward Declarations) to reduce the compile time. – Kriateive Jan 03 '13 at 05:28
  • check the second link that I have mentioned. The post tells in detail on how you can reduce the compilation time – abnvp Jan 03 '13 at 05:34

1 Answers1

0

The link provided above will give you a detailed explanation. Just to put it in a lighter way I am adding a few more things.

If you change something in a CPP file only that file will get recompiled. If it is a header file then it will be a different story. If you have a header file included across multiple modules and when you make changes to that header file, all the associated CPP files will get compiled and again that is the way it should be. So you need to be careful while writing the code if you really care about this aspect. At a later stage it will be difficult to manage such things.

Regarding the compilation of some files even if you don't change anything may happen when

1] we tell the compiler to do so.

2] some CPP or header files are generated or modified automatically while run your build

3] there is a change in file time stamp

4] there is a change in folder name/structure

Last but not least, also try changing the code lite build target.

These are the possibilities I know. There will be more [definitely :)]...

NeonGlow
  • 1,659
  • 4
  • 18
  • 36
  • Yes the links above were very helpful. Reduced some of my cpp files from recompiling but still not all. No, i am not generating any files during compile time. Still I find there are files which get recompiled even when nothing is changed in the whole project. – Kriateive Jan 03 '13 at 10:36
  • @Kriateive : Please check 3rd and 4th are not the case. Try changing code lite build target option if available. – NeonGlow Jan 03 '13 at 12:39
  • Thanks for the help. I finally figured out the problem using --debug=vi with makefile generated by Codelite. The problem was it had been listing some files as prerequisite which were actually deleted. Hence, on issuing make each time, as it could not find the prerequisites, it issued the commands for those set of files. The recursive dependencies made the matter worse. Deleting and regenerating the makefile worked fine. But the above mentioned links and your tips helped me to reduce the dependencies and improve the rebuild time for small changes in the project.Thanks :) – Kriateive Jan 05 '13 at 06:00
  • @Kriateive : Wonder why it was not flagging an error for deleted files. If you are sure about the solution you may put it as answer instead of comment. – NeonGlow Jan 05 '13 at 07:27