Fatal error c1010: Unexpected File ending when searching for pre-compiled Headers

Source: Internet
Author: User

Error Description: Fatal error c1010: Unexpected File ending when searching for pre-compiled headers. Have you forgotten to add "# include" stdafx. H "to the source ""?


Error analysis:       The cause of this error is that the file is not ended as expected when the compiler looks for the pre-compiled directive header file (default # include "stdafx. H. No header file "stdafx. H" is found for pre-compilation instructions ".     (Because every CPP file attribute in the project uses the precompiled header (/YU) by default, but the added third-party file does not include "stdafx. H "indicates the pre-compilation header, so the compiler does not find it in this CPP file until the end)       This problem occurs when I add an existing. h and. cpp file to MFC by adding a file. These. h and. cpp files belong to the Standard C ++ open source code category and have no deeper relationship with MFC.
Solution: 1. 1) In Solution Explorer, right-click the corresponding one. CPP file, click "properties" 2) in the configuration properties on the left, click "C/C ++", and click "pre-compile Header" 3) change "Create/use precompiled header" in the first line on the right, and change the option from "use precompiled header (/YU)" to "do not use precompiled header" 4) Note: every error. CPP must be changed like this ~ Work hard ~ II. (not recommended) 1) Right-click the project in solution, and click Properties 2) in the configuration property-> C/C ++-> pre-compilation header, "Use the pre-compilation header (/YU) "change to" not applicable to precompiled headers ". This will make the compilation process very slow each time.
Note: 1) It seems that you can also include stdafx. h directly on the. cpp header file. But I didn't try to modify it because I didn't want to break the standard of the source code. ^_^ 2) I felt that VC was lagging behind in recognition and compilation. Maybe it was too powerful, I didn't have to worry about it. I still need to manually modify it ~ 3) I miss QT a bit ......   Additional information: Source: http://blog.csdn.net/hotandhot/archive/2006/10/23/1346195.aspx

I. concept:

1. Pre-Compilation: the compiler first compiles a file (called the pre-compilation header file) and saves the compilation result, if other source files include the pre-compiled header file, the required information is automatically extracted from the compilation result for compilation.

2. precompiled header file: The file used to save the compiled symbolic information (. PCH as the suffix)

3. Create precompiled header file ): let's say that source file a uses file B to "generate the pre-compilation result file", which means to save the compilation result of "B" to the pre-compilation result file when compiling. If you use the wizard, file a is "stdafx. cpp", and file B is "stdafx. H ". In stdafx. cpp, there is only one line of statement:

# Include "stdafx. H"

4. Use the pre-compiled header (using precompiled header): A source file (. CPP) through "stdafx. h. if. the first include statement of CPP is # include "stdafx. H ", then directly obtain the results of the pre-compiled result file, and no longer recompile" stdafx. h"

2. How does the wizard work?

1. Set the pre-compilation option of "stdafx. cpp" to "generate the pre-compilation result file" through the "stdafx. H" file ".

2. The pre-compilation options of other source files are set to "use the pre-compilation Header" through "stdafx. H"

Iii. Usage principles?

1. Write all the relatively stable header files (such as CRT, STL, and third-party fixed libraries) in stdafx. h. (Whether to use stdafx. h depends on your personal preferences, but use stdafx. h can be consistent with the Wizard)

2. Add # include "stdafx. H" to the first line of all source files ".

3. For some unmodifiable source files (if the public code does not have the permission to modify the code), set its pre-compilation option to "do not use the pre-compilation Header ". Note that you must not select "automatically generate pre-compiled headers" because it will. the result of H is rushed out (I don't know if it is a bug or a design problem ,. ^_^ .).

Iv. Q &

Q. Why not all of them use "automatically generate pre-compiled header files "?

A. There is no difference between "automatically generate pre-compiled header files" and "nothing". The compilation speed is not significantly improved.

Q. When manually adding a new source file to the project, similar errors often occur:

Fatal error c1010: unexpected end of file while looking for precompiled header Directive

A. Because the default setting of the Wizard is "using precompiled headers", the newly added file does not include "stdafx. H" in the first line ". The solution is either to "do not use the pre-compiled Header", or to add a line # include "stdafx. H"

Q. Adding stdafx. h and stdafx. cpp seems to be bound to the compilation platform. No

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.