Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>What are precompiled headers?</strong></p> <p>Often C++ source files include headers from external libraries. In Windows you include <code>windows.h</code>. These header files can be very large and they take some time to process. Each time you compile a C++ file the compiler has to read and process thousands of lines from these header files. But external libraries don't change and you can save a lot of time if you only process these files once and save the result.</p> <p>A precompiled header is simply a bunch of header files that has been processed to an intermediate form that later can be used by the compiler again and again.</p> <p><strong>Precompiled headers in Visual C++</strong></p> <p>In Visual C++ it is customary to <code>#include</code> all your non-changing header files in <code>stdafx.h</code>. You then instruct the compiler to create the precompiled header <code>stdafx.pch</code> while compiling <code>stdafx.cpp</code> which does nothing but include <code>stdafx.h</code>. If you want to use the precompiled header in another <code>.cpp</code> file you have to include <code>stdafx.h</code> as the first include file and the instruct the compiler to use <code>stdafx.pch</code> for your precompiled header.</p> <p>If you get an error about not including <code>stdafx.h</code> you simply have to instruct the compiler to not use a precompiled header for that particular source file. (Or you can include <code>stdafx.h</code>.)</p> <p><strong>Precompiled header settings for individual source files</strong></p> <p>Visual C++ allows you to control the compiler settings for the entire project and for individual files. To access individual properties you select the source file in the solution explorer, right click it and select <em>Properties</em> from the context menu. The options for precompiled headers are found at <em>Configuration Properties</em> => <em>C/C++</em> => <em>Precompiled Headers</em>. If you modify these settings you will often want to do that for all configurations (e.g. <em>Debug</em> and <em>Release</em>).</p> <p>When you are using precompiled headers you will have a setting for the entire project that instructs the compiler to use <code>stdafx.pch</code> for the precompiled header. The <code>stdafx.cpp</code> will have an individual settings that instructs the compiler to generate <code>stdafx.pch</code>, and if you have some source files that doesn't include <code>stdafx.h</code> you can set individual settings on these to not use precompiled headers.</p>
 

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