Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>The problem</h2> <p>Let's say you have a list of headers you use that you know won't change. For example, the C headers, or the C++ headers, or Boost headers, etc..</p> <p>Reading them for each CPP file compilation takes time, and this is not productive time as the compiler is reading the same headers, again and again, and producing the same compilation result for those same headers, again and again.</p> <p>There should be some way to tell the compiler those headers are always the same, and cache their compiled result instead of recompiling them again and again, no?</p> <h2>The solution</h2> <p>The Pre-Compiled Headers takes that into account, so all you need is to:</p> <ol> <li>Put all those common and unchanging includes in one header file (say, StdAfx.h)</li> <li>Have one empty CPP file (say, StdAfx.cpp) including only this one header file</li> </ol> <p>And now, what you need is tell the compiler that StdAfx.cpp is the empty source that includes the common and unchanging headers.</p> <p>This is where the flags /Yc and /Yu are used:</p> <ul> <li>Compile the StdAfx.cpp file with the /Yc flag</li> <li>Compile all the others CPP files with the /Yu flag</li> </ul> <p>And the compiler will generate (when needed) a pre-compiled header file from the StdAfx.cpp file, and then reuse this pre-compiled header file for all other files marked with /Yu.</p> <h2>Note</h2> <p>When you create a new project, old versions of Visual C++ (6 and 2003, if I remember correctly) would activate the precompiled headers by default. Recent ones offer the choice of activating them of not.</p> <p>You should create a new VC++ project with the PCH activated to have a working version of PCH-enabled project, and study the compilation options.</p> <p>For more information about PCH, you can visit the following URL:</p> <ul> <li><a href="http://msdn.microsoft.com/en-us/library/szfdksca.aspx">http://msdn.microsoft.com/en-us/library/szfdksca.aspx</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload