Atal error c1010: unexpected end of the file when searching for the pre-compiled header. Have you forgotten to add "# include" stdafx. H to the source?
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: this error occurs when the compiler looks for pre-compiled directive header files (default # include "stdafx. H"), the file is not expected to end. 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.) My problem occurs when I add a file, add an existing project to the MFC. H and. CPP 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) "Changing to" not applicable to precompiled headers "will make the compilation process very slow every time. Note: 1) It seems that the pre-compiled headers can be directly stored in. include stdafx on the CPP header file. h. 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. Do I always think stdafx. h and stdafx. cpp are bound to the compilation platform and are not portable?
A. Actually, there is no problem with writing stdafx. h. My solution is (stdafx. H content ):
-Begin of file stdafx. h
# Ifdef _ Win32
# Include "win. H" // indicates the public header file in the window.
# Else
# Include "Linux. H" // generic public header file in Linux
# Endif
# Include "CRT. H" // Generic C standard library
# Include "STL. H" // generic reference STL Library
-End of File
Or a little simpler. If it is not a VC compiler, stdafx. H will not write anything!