INFO: AppWizard and Precompiled Header Files
ID: Q119329
|
The information in this article applies to:
-
The AppWizard, included with:
-
Microsoft Visual C++ for Windows, 16-bit edition, versions 1.0, 1.5, 1.51, 1.52
-
Microsoft Visual C++, 32-bit Editions, versions 1.0, 2.0, 2.1, 4.0, 5.0, 6.0
SUMMARY
When you use AppWizard to generate a starter application, it sets up your
project to use a precompiled header (.PCH) file. Precompiled headers help
to speed up compilation when a group of files in a project do not change.
In the case of Microsoft Foundation Class (MFC) applications generated by
AppWizard, the group of files that do not change are the standard MFC
header files.
AppWizard puts the line "#include 'stdafx.h'" as one of the first lines in
every .CPP file in a project. Because of the compiler options being used by
projects generated with AppWizard, anything up to and including "stdafx.h"
in a .CPP file is considered by the compiler to be part of a precompiled
header.
The problem with this is that when you edit the .CPP files and insert
#includes, #defines, declarations, or other code before the "#include
'stdafx.h'" line, all of it is ignored by the compiler. This is the correct
behavior because when the compiler is using the precompiled header, it
starts to compile the code in the .CPP file after skipping past the
"stdafx.h" line.
This behavior can lead to compiler errors that do not seem to make sense,
because it appears that you are including all the needed declarations and
header files in the .CPP file. For example, some of the errors that may
result are the following:
- error C2065: 'CTestClass' : undeclared identifier
- error C2146: syntax error : missing ';' before identifier 'tc'
- error C2064: term does not evaluate to a function
Even if the code compiles without errors, it may not run the way you expect
to if there is code meant to be conditionally included or excluded based on
whether a preprocessor macro was defined. This can occur if the line with
the #define was inserted before the "stdafx.h" line. To avoid unexpected
compiler errors or unexpected behavior in your application, make sure any
code you add to an AppWizard-generated .CPP file comes after the "stdafx.h"
line.
REFERENCES
"Visual C++ for Windows Programming Techniques" manual, chapter 1,
"Using Precompiled Headers."
"Visual C++ for Windows NT Programming Techniques" manual, chapter 10,
"Using Precompiled Headers."
Visual C++ Books Online topic "Using Precompiled Headers" in the
"Visual C++ User's Guide" chapter on "Working With Projects."
Additional query words:
random incorrect
Keywords : kbwizard kbVC100 kbVC150 kbVC151 kbVC152 kbVC200 kbVC210 kbVC400 kbVC500 kbVC600 kbGrpDSTools
Version : WIN3X:1.0,1.5,1.51,1.52;WINNT:1.0,2.0,2.1,4.0,5.0,6.0
Platform : NT WINDOWS
Issue type : kbinfo
|