Sunday, November 1, 2009

fatal error C1010 - unexpected end of file while looking for precompiled header directive

Once, when I was trying to compile a program with Visual C++ .NET (dot-net), initially written for the Apple Macintosh for Objective-C. I keep getting the following error message:

"fatal error C1010 - unexpected end of file while looking for precompiled header directive."

I looked into the header file but needed help finding something.


Actually, the answer was simple i solved it by the following way.

MFC programs use many libraries, requiring the use of many header files. To save time, the compiler tries to precompile most of these header files and use the predigested data instead of reading through all of these header files on every compilation. There are several ways to do this. The standard method for MFC programs is to lump all of these standard header file references into one header file ("stdafx.h"). If you just have to ask what "stdafx" means, it comes from the early name of MFC, AFX (application framework).

When compiling each source (.cpp) file, the compiler skips through the source code, looking for the directive:


#include "stdafx.h"


Once it finds this directive, it substitutes the precompiled header information and compiles the rest. If your source file doesn't contain this directive, you get the C1010 error described above.

The simple solution is to insert the include directive to your source file before any other library references or code.

1 comment:

  1. hi,

    i added the #include "stdafx.h" at the begginning of every .cpp code still the error persists please please help me .....

    ReplyDelete