The "Fatal error c1010" solution and pre-compilation header concept appear in VC compilation.

Source: Internet
Author: User

"Fatal error c1010: unexpected end of file while looking

Precompiled header Directive ", but I have checked that there is no error in the program. How can this problem be solved?

  (1) it must be a newly added class. cpp file that does not start with stdafx. H. Just add it at the beginning of the file.
  (2) You can right-click the CPP file in the project and select setting. In the C/C ++ column, select precompiled headers and set the first option, select not to use the pre-compiled header to solve this problem.

 

I. Functions of pre-compiled Headers

   If the project has many large files and several header files are frequently used

    1. Write all these header files to a header file, such as preh. h.

    2. Write a preh. C with only one sentence: # include "preh. H"

    3. For preh. C, set creat precompiled headers in project setting. For other. c files, set use precompiled header file.

 [Effect]: No precompiled header is needed. After compilation, I can go to the toilet. When compiling with precompiled headers, I can stand up and stretch out, and the activity is almost the same.

 

Ii. concepts of pre-compiled Headers

  The so-called pre-compilation header is to pre-compile the part of the code in a project and put it in a file (usually. PCH Extension). This file is called the precompiled header file. The pre-compiled code can be any C/C ++ code -------- or even an inline function, however, it must be stable and won't be changed frequently during project development.
  If the code is modified, re-compile the pre-compiled header file. Note that it takes a lot of time to generate a pre-compiled header file. The pre-compiled header file is usually large, usually 6-7 M. Clear unused pre-compiled header files in time.

 

Iii. Use of pre-compiled Headers

  To use the pre-compiled header, we must specify a header file, which contains code that we will not change frequently and other header files. Then we use this header file to generate a pre-compiled header file (. PCH file) We all know stdafx. h. Many people think that this is a system-level file provided by VC, a header file carried by the compiler. Actually not. This file can be of any name. We will examine a typical pre-compiled header file of the MFC dialog based program generated by Appwizard. (Because Appwizard specifies how to use the pre-compiled header file. The default value is stdafx. H, which is the name of VC ). We will find that this header file contains the following header files:

# Include <afxwin. h> // MFC core and standard components
# Include <afxext. h> // MFC extensions
# Include <afxdisp. h> // MFC automation classes
# Include <afxdtctl. h> // MFC support for Internet Explorer 4 common controls
# Include <afxcen. h>

 Then how do we specify it to generate the pre-compiled header file. We know that a header file cannot be compiled. Therefore, a CPP file is required to generate the. PCH file. The default value of this file is stdafx. cpp. There is only one code in this file: # include "stdafx. H ". The reason is taken for granted. We only need to compile it. All we need is its. cpp extension.

 

  You can use the/YC compilation switch to specify stdafx. cpp to generate a. PCH file, and use the/FP compilation switch to specify the name of the generated PCH file. Open the project-> setting-> C/C ++ dialog box. Point category to the precompiled header. In the tree view on the left, select the entire project options (the white place in the lower right corner) and you can see/FP "Debug/PCH. PCH ", which is generated by the specified. the name of the PCH file. The default value is usually <Project Name>. PCH (my example project name is PCH ).

  Then, select stdafx. cpp in the Tree View on the left. // select only one CPP file!

  In this case, the original project option becomes the source file option (originally a project, but now a file ).

  YC switch,/YC is used to specify this file to create a PCH file. The file name after/YC is the header file that contains stable code. Only one file in a project can have the YC switch. VC compiles stdafx. cpp into an OBJ file and a PCH file based on this option.

  Select another file and select another CPP file. Here, precomplier selects use ??? Header file is the stdafx. h file that we specified to create the PCH file. In fact, use the settings in the project,/YU "stdafx. H ".

 

 In this way, the pre-compiled header file is set. Note:

  1): If/Yu is used, that is, pre-compilation is used. the beginning of the CPP file, including the one that specifies to generate the PCH file. h file (default is stdafx. h) otherwise there will be problems. If you do not include this file, you will be told to unexpected file end. If you do not include it at the beginning, you can try the following to understand it. It is absolutely amazing ?..

  Fatal error c1010: unexpected end of file while looking for precompiled header directive generating code...

 

  2) If you accidentally lose the PCH file, many abnormal behaviors will occur during compilation. Based on the above analysis, you only need to let the compiler generate a PCH file. That is to say, recompile stdafx. cpp (that is, the CPP file of the specified/YC. Of course you can rebuild all. Simply select the CPP file and press Ctrl + F7. Otherwise, it would be a waste of time.

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.