gpt4 book ai didi

c++ - 强制包含可以与 Visual C++ 中的预编译 header 一起使用吗?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:07:18 26 4
gpt4 key购买 nike

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

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

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

// 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:查找预编译 header 时文件意外结束。您是否忘记将“#include "stdafx.h"”添加到您的源代码中?

我觉得应该可以用/FI来指定预编译头。

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

最佳答案

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

关于c++ - 强制包含可以与 Visual C++ 中的预编译 header 一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47751372/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com