View Single Post
  #5   Spotlight this post!  
Unread 01-06-2016, 08:51 AM
heuristics heuristics is offline
Registered User
FRC #3634
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Trumbull, CT
Posts: 21
heuristics is on a distinguished road
Re: Speeding up C++ compile times

Another way to speed up C++ compile times significantly is to set up compilation with precompiled headers. The way it basically works is you set up a new compilation unit designated as your precompiled header that will be used as a compilation checkpoint for all your other compilation units (typically .cpp files).

If you are unfamiliar with C++ compilation, for every compilation unit, the compiler needs to reparse every single header included throughout the include chain of that unit. If your system library headers are extensive (like for example windows.h can include hundreds of other headers) this can make compiling each unit take a long time. By including commonly included but infrequently changed headers into your precompiled header unit, you are giving the compiler a checkpoint at which to begin compilation for each other compilation unit so it doesn't have to reparse those headers that were included in your precompiled header.

If you do have to change any of the headers included by your precompiled header, the entire project will need to be rebuilt. This is why you only want to include infrequently changed headers.

You'll have to look up how to do this with the FRC C++ toolchain as I've only set it up with MSVC/VS, but the general process is the same.
-Add a new .cpp that all it does is include a new .hpp.
-In your new .hpp, include any headers that are commonly included (WPILib/STL headers are probably all you want to include).
-Designate your new .cpp as the precompiled header compilation unit.
-Include your new .h at the *very top* of all your existing .cpp files.
Reply With Quote