【问题标题】:Can force include be used with pre-compiled headers in Visual C++?强制包含可以与 Visual C++ 中的预编译头一起使用吗?
【发布时间】:2017-12-11 10:55:52
【问题描述】:

如果为单个 cpp 文件(即不是整个项目)设置了 /Yu,是否可以设置 /FI 以指定要包含的头文件或必须包含头文件,例如 @987654325 @如果/Yu"stdafx.h"传递给CL?

以下所有导致基本相同的错误...

C:\path\to\stdafx.htest.cpp 有一个标题,就像这样......

// Not including `stdafx.h`
void foo() {}

其中任何一个要编译...

CL.exe /c /Yu"stdafx.h" /FI"C:\path\to\stdafx.h" test.cpp
CL.exe /c /Yu /FI"C:\path\to\stdafx.h" test.cpp
CL.exe /c /Yustdafx.h /FIC:\path\to\stdafx.h test.cpp
CL.exe /c /Yu /FIC:\path\to\stdafx.h test.cpp

fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

在我看来应该可以使用/FI来指定预编译的头文件。

这个答案似乎表明它甚至是首选方法 https://stackoverflow.com/a/11052390/6225135

【问题讨论】:

  • 更多表明它有效的答案:stackoverflow.com/a/11403418/15416。 @VTT:/FI 被描述为隐含的#include
  • 问题可能出在stdafx.h 不是 C:\path\to\stdafx.h 吗? IOW,问题可能是 VC++ 进行字符串比较,而不是尝试确定两个名称是否引用同一个文件。
  • 是的,就是这样,@MSalters 我有/Yu"stdafx.h"/FI"C:\full\path\to\stdafx.h",这是一个禁忌,即使它们是等价的,它们也必须是相同的。如果您回复,我将接受它作为答案。谢谢!

标签: c++ visual-c++ precompiled-headers


【解决方案1】:

问题是stdafx.h 不是C:\path\to\stdafx.h。 VC++ 进行字符串比较。您需要将C:\path\to\ 添加到包含路径,因此您可以只使用/FI"stdafx.h"

【讨论】:

  • /FI:stdafx.h 将寻找 :stdafx.h 并且不会工作
【解决方案2】:

经过一些实验,我设法让它正常工作。结果我所要做的就是提供 /Yu

相同的值
/FI"stdafx.h"

【讨论】:

    猜你喜欢
    • 2010-11-16
    • 1970-01-01
    • 2014-01-09
    • 2010-12-08
    • 1970-01-01
    • 2011-06-13
    • 2015-10-03
    • 1970-01-01
    • 2018-04-08
    相关资源
    最近更新 更多