title: In c++ why does it take so much longer to compile lots of smaller files than larger files?
body: <p>I recently split some very large files in my c++ project down into many smaller files (basically one file per class). This has over doubled the compilation time and also enlarged the resulting executable from 1.6mb to 2.4mb. Why has this made such a huge difference?</p>
  
  <p>Is this a direct result of having to include a few headers in a lot of files as opposed to just a few?</p>
  
  <p><strong>Comiler options:</strong></p>
  
  <p>g++ -Wall -Wextra -g -ggdb -std=c++0x</p>
  
  <p>The executable size I am referring to is after running strip -s executable.</p>
  
  <p><strong>Sizes:</strong></p>
  
  <p>Before with debug symbols: 16MB</p>
  
  <p>After with debug symbols: 26MB</p>
  
  <p>Before without debug symbols: 1.5MB</p>
  
  <p>After without debug symbols: 2.4MB</p>
  
  <p><strong>Additional question:</strong></p>
  
  <p>I'm already using precompiled headers by putting the headers in a pch.hpp and then using the -include pch.hpp option in my g++ flags. Is this the optimal way to do this with gcc? It seems to have very minimal impact on compile times. The only headers currently not being precompiled are apart of the project and subject to change as the project is under heavy development.</p>