Fatal error C1010: Unexpected end of file encountered while looking for precompiled header

Source: Internet
Author: User

--Fatal error C1010: Unexpected end of file encountered while looking for precompiled header. Have you forgotten to add "#include" stdafx.h "to the source"--

The error is clearly pointing to. cpp does not include "stdafx.h", but there is also an error when you select "Do not use precompiled headers" in the precompiled header of the project properties, c/C + +.

Find found to be the result of a third-party file that was originally added to the project. "StdAfx.h" is not found in these CPP files until the end.

How to resolve:

To set the properties of all. cpp files in a third-party file, C + +, precompiled headers, select Do not use Precompiled headers. (*.cpp can be set with multiple options)

Related pre-compilation concepts http://blog.csdn.net/hotandhot/article/details/1346195

First, the concept: 1, Pre-compilation: is the compiler to compile a file (called Precompiled Header File), and then save the compilation results, and then if there are other source files include this "precompiled header File", then automatically extract the required information from the compilation results compiled. 2. Precompiled result file (precompiled header File): The file that is used to save the compiled symbol information (. PCH as suffix) 3, Generate precompiled Result file (Create Precompiled Header File): We say that the source file A through file B "Generate precompiled Result file" refers to compile a when compiling the results of compilation B is saved to the precompiled result file. General use of the wizard, a file is "Stdafx.cpp", b file is "stdafx.h". Stdafx.cpp: #include "stdafx.h" 4, Use Precompiled header (using precompiled header): We say that a source file (a.cpp) is "stdafx.h" To use precompiled results refers to compiling a.cpp, if the A.cpp first row include statement is # include "stdafx.h", then directly take the results of the precompiled result file, no longer recompile "stdafx.h" second, how does the wizard do? 1. The precompiled option to set "Stdafx.cpp" is to "generate the precompiled result file" through the "stdafx.h" file. 2, the other source files pre-compilation option is set through "stdafx.h" to "Use precompiled header" Three, the use of the principle? 1, the relatively stable header files (such as CRT,STL, third-party fixed library) are all written in the stdafx.h. (whether to use stdafx.h to rely on personal preferences, but use stdafx.h can be consistent with the wizard) 2, all source files are added to the first line of "stdafx.h". 3, some can not modify the source file (if the public code, do not have permission to modify the code), set his pre-compilation option is "Do not use precompiled header." Note that you must not select "Automatically generate precompiled headers" because this will flush out the results of stdafx.h (this is not a bug or a design problem,. ^_^. )。 Four, Q&aq, why not all use "Automatically generate precompiled header file"? A, "Automatic generation of precompiled header Files" and nothing is no different, the compilation speed is not improved. Q, when manually adding a new source file to the project, a similar error often occurs: Fatal error c1010:unexpected end of file while looking for Precompiled header Directivea, because the wizard default setting is "Use Precompiled header", but your newly added file does not contain "stdafx.h" in the first line. The solution is either modified to "do not use precompiled headers", or add a line of # include "StdAfx.h" Q, plus stdafx.h and stdafx.cpp always feel that the compiler platform is bound, not portability? A, in fact, pay attention to the wording of stdafx.h no problem.    My solution is (stdafx.h content): –begin of File Stdafx.h#ifdef _win32#include "Win.h"//refers to the Common header file under window #else#include "Linux.h" Refer to the common header file under Linux #endif#include "Crt.h"//refer to C standard library # include "stl.h"//Generic STL library –end of file or simpler, if not VC compiler, then StdAfx . h do not write any content!

Fatal error C1010: Unexpected end of file encountered while looking for precompiled header

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.