C++零食:VC中使用ForceInclude来强制包含stdafx.h

在使用VC编程中,为了加快编译,vc编译器提供了预编译的功能。即在cpp代码中包含stdafx.h,那么就可以使用到预编译。

如下所示:

#include "stdafx.h"

class Demo
{
public:
    Demo(void);
    ~Demo(void);
};

注意: #include “stdafx.h” 是自己手动写的,默认是没有的。

因此,有时总会出现忘记写这个的事情,这时候编译器就会报一个错误:

Error    1    fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?    d:\3_code\vc\forceincludedemo\forceincludedemo\demo.cpp    11   

要是能不添加stdafx.h也能有预编译这个功能就好了。

 

ForceIncludes

经过一番查找,我发现在编译器中提供了一个/FI (Name Forced Include File)的选项。

通过使用这个选项就可以避免这样的事情发生了。

这个参数的设置在工程的“属性”对话框中,具体是C++下面Advanced中的Force Includes属性。

如图:

image

 

 

参考资料

/FI (Name Forced Include File)

http://msdn.microsoft.com/en-us/library/8c5ztk84.aspx

posted @ 2010-10-16 23:33  林杰的博客  阅读(1739)  评论(1编辑  收藏  举报