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

Source: Internet
Author: User

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

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.