[Reprinted] the solution and principle of the pre-compiled header file cannot be opened by error

Source: Internet
Author: User
Tags change settings

1. Use VC. Net to edit the program and press Ctrl + F7. the following error occurs:
Fatal error c1083: Unable to open the pre-compiled header file: "Debug/ugface. PCH": no such file or directory
Solution: Modify project-> properties-> C/C ++-> pre-compilation header-> do not use the pre-compilation header.

2. When I learned to use the first routine of Visual C ++ 6.0, I got an error. after the Wizard is used to generate the first project based on the dialog box, an error always exists after I input the project one word by one based on the source program in the book:
Fatal error c1010: unexpected end of file while looking for precompiled header directive. after countless times, I decided to include the header file statement: Include "stdafx. H "Reserved (and I deleted it before, because the example in the book does not contain this sentence .) okay. That's right. why? I am puzzled.
When I came to my VC source code directory, I noticed that the debug folder under each project is very large and the extension is. PCH occupies the vast majority of files, and I deleted it as if it had no effect on program compilation and running. So with curiosity about the. PCH file, I found my questions on the Internet. This is what VC ++ 6.0 brings to us: Pre-compiled header files. Pre-compiled header files (generally with the extension. PCH) are precompiled into a file (. PCH) for the stable code in a project. These pre-compiled codes can be any C/C ++ code or even inline functions, but they are relatively stable throughout the project, that is, the code that is not frequently modified during the project development process.
Why do we need to pre-compile the header file?
In a word: it increases the compilation speed. Generally, the compiler compiles data in files. If you modify a file in a project, all files must be re-compiled, including all the items in the header file (eg. macro macro, Preprocessor preprocessing), while in VC programs, the content contained in these header files is often very large, and compilation takes a long time. But they are not often modified and are relatively stable. Re-compiling all files of the entire project for a single small file leads to a reduction in compilation efficiency, so the. PCH file is introduced.
How to use pre-compiled header files to increase Compilation speed?
To use a precompiled header file, you must specify a header file (. h), it contains code that we do not often modify and other header files, and then uses this header file to generate a pre-compiled header file (. PCH), the default VC header file is stdafx. h. Because the header file cannot be compiled, we still need one. CPP file as a bridge. The default VC file is stdafx. CPP, the only code in this file is: # include "stdafx. H ". Next, use it to generate the. PCH file, which involves several important pre-compilation commands:/YU,/YC,/Yx,/FP. In short,/YC is used to generate the. PCH file compilation switch. In the category of project-> setting-> C/C ++, select the precompiled header for compilation in the Tree View on the left. the. CPP file (default: stdafx. CPP), you can see the/YC switch, which indicates whether the file is generated after compilation. PCH file (possibly/YC c Indicates create ). The/FP command specifies the name and path of the generated. PCH file (maybe/FP p represents path ). The U of/Yu is the use. This/YU command will be available in files that contain. H files in the project. If Automatic automatic... is selected, the original location of/YC is replaced with the/Yx command. If Automatic is selected, the compiler will check whether the. PCH file has been generated before each compilation. If yes, The. PCH file will be compiled again.
Note:
A. In fact, the default header file and CPP file stdafx. h and stdafx. cpp generated by the appzard Project Wizard can be any name. The reason is very simple. But if you want to do this, remember to modify the pre-compiled parameters (/YC,/YU,/Yx,/FP) in the corresponding project> setting.
B. it is used in any header file that includes the header file to be precompiled. the start of the project file of the PCH file must be at the beginning. You must include the specified file to be generated. the. h file (. the CPP file is included. The default value is stdafx. CPP), if not included, it will generate the first error. if it is not at the beginning, it will lead to unexpected and inexplicable errors. If you do not believe it, should it be a try?
C. pre-compiled file. PCH generation takes a lot of time, and it also occupies disk space after generation, usually 5-6 M. Note that it is useless to clean up after the project is completed. PCH file to save disk space.
D. if it is lost or deleted. when you need to modify the project file later. CPP file (default: stdafx. CPP) re-compile once to generate again. PCH file. Do not use F7 or rebuild all.


I have encountered another situation before: Create a project and find a CPP file at will. Press Ctrl + F7 and the system will prompt: Fatal error c1083: Unable to open the pre-compiled header file: "Debug/xxx. PCH ": no such file or directory (where XXX is the project name) This is also the same reason, for VC stdafx. the H header file is not compiled. It can also be solved as follows: F7 first, then ctrf + F7 after compilation.

Note: the precompiled header file for vs smart device programs (such as wm5) is stdafx. h. Change settings in project> XXXX Properties> Configuration Properties> C/C ++> the first item on the right of the pre-compilation Header

For your security, please only open the URL with reliable source

Open website {
Function onclick ()
{
Function onclick ()
{
Share. safelink. Close (); Return false;
}
}
} "Href =" http://writeblog.csdn.net/# "> cancel

From: http://hi.baidu.com/andywangcn/blog/item/7d8da5072516fc7003088172.html

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.