Stdafx. h

Source: Internet
Author: User
Introduction

Standard Application Framework extensions header file pre-compilation refers to the use of some MFC standard header files (such as Windows) in a project. h. afxwin. h) pre-compilation. Later, this header file will not be compiled and only the pre-compilation results will be used. This will speed up compilation and save time. The precompiled header file is generated by compiling stdafx. cpp and named after the project name. Because the precompiled header file is suffixed with "PCH", the compilation result file is projectname. PCH. The compiler uses the pre-compiled header file through a header file stdafx. h. The stdafx. h header file name can be specified in the project compilation settings. The compiler considers that all commands in the # include "stdafx. H "the previous code is pre-compiled, and it skips # include" stdafx. H "command, using projectname. PCH compiles all the code after this command. Therefore, the first statement of all the MFC implementation files is: # include "stdafx. H ".

An application usually needs to be released without interruption during the development process. Windows program included standard. h testing case
It is very huge, but the content remains unchanged. The timer has a lot of time on it. The precompiled header is used to store the results after the first batch operation of. h. The second batch operation can be taken directly from the disk for use. This concept has long been implemented in Borland C/C ++, and Microsoft is not available until visual c ++ 1.0.

----------------- From MFC

Detailed working principles and functions

There is no function library in stdafx. h, but some environment parameters are defined so that the compiled program can run in a 32-bit operating system environment. The include files for Windows and MFC are very large. Even if there is a fast processing program, it takes quite a long time to compile the program. Since each. cpp file contains the same include file, it is silly to process these files repeatedly for each. cpp file. To avoid this waste, Appwizard works with the VisualC ++ compiler as follows: ◎ Appwizard creates the stdafx file. h. This file contains all the mfcinclude files required by the current project file. This file can change with the selected options. ◎ Appwizard, then stdafx. cpp is created. This file is usually the same. ◎ Then Appwizard creates the project file, so that the first compiled file is stdafx. cpp. ◎ When Visual C ++ compiles the stdafx. cpp file, it stores the result in a file named stdafx. PCH. (The extension PCH indicates the precompiled header file .) ◎ When Visual C ++ compiles each subsequent. cpp file, it reads and uses the. PCH file it just generated. VisualC ++ does not analyze windowsinclude files any longer, unless you have edited stdafx. cpp or stdafx. h. This technology is very sophisticated. Don't you think so? (Also, Microsoft is not the first company to adopt this technology, Borland is .) In this process, you must follow the following rules: ◎ any. cpp file you write must first contain stdafx. h. ◎ If you have a majority of. cpp files in the project file that require. H files, add them to stdafx. H (back) and pre-compile stdafx. cpp. ◎ Because the. PCH file has a lot of symbolic information, it is the largest file in your project file. If your disk space is limited, you want to delete the. PCH file from the project file you have never used. They are not required when the program is executed, and they are automatically re-established as the project file is re-established.
How to understand its principles

In other words, when we use Appwizard to automatically generate certain projects, the system will automatically include the header files in stdafx. h: Include the stdafx directly. h file. because CPP contains the same include file for different source files in the same project. it is silly to include these files repeatedly in CPP files. Of course, if you don't need MFC, you don't need it. That is, include stdafx. h In each. cpp file is equivalent to include other files such as iostream. h.
Differences from stdio. h

We usually need to first include this stdio when compiling C Programs with TC or VC. h header file. This header file contains the definitions of scanf and printf functions. If we do not include this file at the beginning of the program, you will not be able to call the above two functions, it actually works with iostream in C ++. H files have similar functions. They are generally in stdafx. the H file is included.

Note:

1. afxwin. H is a required file for MFC programming, including the header files required for running the cstring and cedit classes. It is best to ensure that this sentence is in the first line of the header file; it will also call windows. h. The header package contains the definition of data types, API entry points, and other useful parameter information;

2. the most common problem when using the MFC library for non-MFC projects is windows. h Repeated inclusion error: Fatal error c1189: # error: Windows. h already included. MFC APPs must not # include <windows. h>;

3. # define win32_leanand_mean, refuse to accept the MFC class library in the Windows header file to accelerate the compilation time;

4. AF in afx-afx refers to the abbreviation of application frame. Once a technical development team specialized in application frame, afx was used to name the team, and X had no meaning, it only constitutes a loud slogan, which has been used for a long time.

5. create a new empty project, stdafx in the project. CPP uses the create precompiled header (/YC. CPP is the use precompiled header (/YU) used, and create/use PCH trhough file is stdafx. h

 

(4) stdafx is a pre-compiled header file. You can choose Project/settings... from the VC ++ integrated environment menu.
Project Settings dialog/C ++/Category: check box of precompiled headers/use precompiled header file (. PCH. Stdafx. H files have been used as pre-compiled header files. The pre-compiled header file is the first action before compiling all codes. Parse this file to get the defined structure and parameters. In this way, you do not need to re-Parse each file during compilation. Increase Compilation speed. The stdafx. h name can be changed. You can specify the name of the precompiled header file. This is only useful in VC and is not a feature of C ++. In VC, you can declare the global variables and IDs here.

(5) fatal error c1083: cannot open include file: 'stdafx. H': no such file or directory

A. If there is no stdafx. h at all, why should you include it? Generally, only large projects need to pre-compile the header file. stdafx. h to delete this line # include "stdafx. H"

B Project-> Settings-> C/C ++ category-> precomiled headers select the first not using precompiled headers

In C Project-> Settings-> C/C ++-> project options, delete/FP "Debug/your_project_name.pch" And/YU "stdafx. H. Note that the files originally included in stdafx. h must be included in various. cpp files.

D. Add # include "stdafx. H". (# include "stdafx. H" at the beginning of *. cpp to the front of # include, that is, the front of the program. To use the pre-compiled header file, you need to put it at the beginning of the program, otherwise the content before it will be ignored)

E rebuild all (6) sets the pre-compilation. If # include "stdafx. H" is not added, this error is reported: Fatal error c1010:
Unexpected end of file while looking for precompiled header directive. The compiler uses the pre-compiled header file through a header file stdafx. h. The stdafx. h header file name can be specified in the project compilation settings. The compiler considers that all commands in the # include "stdafx. H "the previous code is pre-compiled, and it skips # include" stdafx. H "command, using projectname. PCH compiles all the code after this command. Therefore, the first statement of all CPP implementation files is: # include "stdafx. H ".

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.