可以将力包括在视觉C 中与预编译的标头一起使用

Can force include be used with pre-compiled headers in Visual C++?

本文关键字:编译 一起 包括 视觉      更新时间:2023-10-16

如果为单个CPP文件设置了/Yu(即整个项目)是否可以设置/FI来指定要包含的标头文件,或者必须随身携带标题文件。例如#include "stdafx.h"如果将/Yu"stdafx.h"传递给CL?

所有以下结果基本相同的错误...

C:pathtostdafx.h的标头和test.cpp喜欢...

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

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

CL.exe /c /Yu"stdafx.h" /FI"C:pathtostdafx.h" test.cpp
CL.exe /c /Yu /FI"C:pathtostdafx.h" test.cpp
CL.exe /c /Yustdafx.h /FIC:pathtostdafx.h test.cpp
CL.exe /c /Yu /FIC:pathtostdafx.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

问题是stdafx.h不是C:pathtostdafx.h。VC 进行字符串比较。您需要将C:pathto添加到Include路径,因此您可以仅使用/FI"stdafx.h"

经过一些实验,我设法使其正常工作。事实证明,我要做的就是提供与/Yu

相同的值
/FI"stdafx.h"