星期五, 一月 26, 2007

unexpected end of file while looking for precompiled header directive

编译CxImage库,有个MFC问题,我不想再敲了,下面是一篇文章,说的挺好的,我贴了。重申一次,I hate mfc
--------------------------------------------------------------------------------

Error message C1010
--------------------------------------------------------------------------------
?
?Error message C1010
If, while building an MFC application, you receive the error message "fatal error C1010: unexpected end of file while looking for precompiled header directive" it means you have run afoul of the compiler's handling of precompiled headers.

What are precompiled headers?
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 a number of ways to do this. The standard method for MFC programs is to lump all of these common 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, which was 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 then begins compiling the rest of the file. If your source file doesn't contain this directive, you get the C1010 error described above.

Fixing the problem
There are two ways to get rid of the error, depending on the file you are trying to compile:

The direct solution is to add the include directive to your source file, before any other library references or other code. This solution is appropriate when the module you are compiling needs to make use of MFC classes (e.g., CString).
If your module is "pure" C++ code (for example, your own "Date" class), with no need to reference MFC at all, then you may prefer not to add the "stdafx.h" include directive. In this case, you can change the project settings to inform MSVC that you are not making use of the precompiled header files. Here's how to do it:
From the Project menu, select Settings ....
Make sure the Settings for selection reflects the project you are building. By default, this will likely be "Win32 Debug".
Expand the Source Files folder in the list on the left, and click once on the source file that you don't want to use precompiled headers.
On the right, select the C/C++ tab.
In the Category combo box, select Precompiled headers.
Select the Not using precompiled headers option.
Repeat for any other files for which you wish to disable precompiled headers (but not for any files created by the Developer Studio AppWizard).
Click OK to close the project settings dialog.

1 条评论:

匿名 说...

.cpp文件开头没包含stdafx.h,在该文件最前面加上即可