在使用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属性。

如图:

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

 

 

参考资料

/FI (Name Forced Include File)

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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-04
  • 2021-07-16
  • 2021-10-09
  • 2022-12-23
  • 2021-06-29
猜你喜欢
  • 2021-05-27
  • 2022-12-23
  • 2021-08-08
  • 2021-11-25
  • 2021-06-11
  • 2021-10-10
相关资源
相似解决方案