0

I am trying to fasten the build by using precompiled headers. I wonder what is the easiest/fastest way to know which files I should include in my "stdafx.h" so that they only build once?

Right now, I iterate over every file, and collect the #include section into one container for all files. Then, I manually count which file is included and how many times, finally I pick the relatively highest counted files and put them in "stdafx.h".

It works, but this is time consuming and I have many projects. Please and thank you.

Sandra K
  • 1,209
  • 1
  • 10
  • 21
  • 3
    I just put third party libraries and system headers there and avoid my own code unless I know its a header that I will not likely have to edit in the future. – drescherjm Oct 16 '19 at 17:34
  • @drescherjm So what is the problem with adding the headers that get changed often? – Sandra K Oct 16 '19 at 17:41
  • You end up making your builds take longer instead of shorter because the precompiled header needs to be regenerated after the change. It also forces more files to rebuild. – drescherjm Oct 16 '19 at 17:42
  • @drescherjm So I am doing it wrong by counting most included files... – Sandra K Oct 16 '19 at 17:47
  • 3
    You want the headers that are not going to change (or are going to change the least). Any changes to the headers included in the pre-compiled header file will cause all the .cpp files that include the pre-compiled header file to be recompiled. So system headers; external libraries; your stable libraries are all good candidates. – Richard Critten Oct 16 '19 at 17:50
  • My project sped up its compile time by 10% by getting rid of precompiled headers. Make sure you carefully measure. – Eljay Oct 16 '19 at 17:50
  • Trust no one. If it's important, profile. – user4581301 Oct 16 '19 at 17:56
  • I see. Ok thank you! – Sandra K Oct 16 '19 at 18:11

0 Answers0