Precompiled header files-stdafx. h and stdafx. cpp

Source: Internet
Author: User

These files are used to build a precompiled header fileProjname. PCH and a precompiled types file stdafx. obj.
These two files are used to create a pre-compiled header file.Projename. PCH and a predefined type file stdafx. obj.

These files are located inProjnameDirectory. In Solution Explorer, stdafx. H is in the header files folder, and stdafx. cpp is located in the source Files folder.
These two files are placed in the project folder. In solution manager, stdafx. H is in the header files folder, and stdafx. cpp is in the source Files folder.

File Name

Description

Stdafx. h

An include file for standard system include files and for project-specific include files that are used frequently but are changed infrequently.

You shoshould not define or undefine any of the _ afx_no_xxx Macros in stdafx. h; see the Knowledge Base Article "PRB: problems occur when defining _ afx_no_xxx ". you can find knowledge base articles in the msdn library or at http://search.support.microsoft.com /.

Stdafx. cpp

Contains the Preprocessor Directive# Include "stdafx. H"And adds include files for precompiled types. precompiled files of any type, including header files, support faster compilation times by restricting compilation only to those files that require it. once your project is built the first time, you will notice much faster build Times on subsequent builds because of the presence of the precompiled header files.

From heart
Stdfx refers to standard application frame extend.
Because the MFC architecture is very large and contains many header files, it takes a lot of time to compile each time. Therefore, we put all common MFC header files in stdafx. h, such as afxwin. h, afxext. h. afxdisp. h. afxcen. H and so on, and then let stdafx. CPP contains this stdafx. h file. In this way, the compiler can identify which files have been compiled, so stdafx. CPP is compiled only once and generates the so-called pre-compiled header file (because it stores the information after the header file is compiled, hence the name ).
If you do not want to compile some MFC header files during programming, you can add them to stdafx. h. Pre-compiled header files can accelerate the compilation process.

Windows and MFC include files are very large, even if there is a quick processProgramIt 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 visual C ++ compiler as follows:

    • Appwizard creates the stdafx. h file, which contains all the MFC include files required for the current project file. This file can change with the selected options.
    • Appwizard then creates stdafx. cpp. 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. Visual c ++ no longer analyzes Windows include files unless you have compiled stdafx. cpp or stdafx. h.
      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.
Related Article

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.