可以将预编译头与 MIDL 生成的文件一起使用吗?

发布于 2024-08-08 02:36:19 字数 166 浏览 4 评论 0原文

我们确实有一个项目,它使用 MIDL 工具来创建特定的标头/iid 和代理文件。使用调用 nmake 的构建后步骤来编译这些文件并与项目的其余部分链接。

是否可以将预编译头与 IDL 生成的文件一起使用?如何注入 #include "stdafx-h" 并删除其他包含的标头?

We do have a project wich uses the MIDL tool to create specific header/iid and proxy files. Those files are compiled and linked with the rest of the project using a post build step that calls nmake.

Is it possible to use precompiled headers with thos IDL generated files? How can I inject #include "stdafx-h" and remove other included headers?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝咒 2024-08-15 02:36:19

使用 /FI 选项(强制包含): “此选项与在命令行、CL 环境变量或命令文件中指定的每个源文件的第一行的 #include 指令中指定带双引号的文件具有相同的效果。”

它不会删除其他标头,但这对于使用预编译标头来说不是必需的...您想要预编译的所有标头都应包含在 stdafx.h 中。然后,如果文件具有包含保护,那么当它们再次包含在源中时就不会出现问题。

示例

生成a.cpp文件:

#include <a.h>
#include <b.h>
//rest of the code

假设您要预编译ahbh。然后创建文件 stdafx.h:

#include <a.h>
#include <b.h>

然后使用 /FI 选项将此 stdafx.h 作为第一个文件包含到 a.cpp 中。如果文件 ahbh包含防护< /a>,将它们留在 a.cpp 中不是问题......

Use the /FI option (Force Include): "This option has the same effect as specifying the file with double quotation marks in an #include directive on the first line of every source file specified on the command line, in the CL environment variable, or in a command file."

It won't remove the other headers, but this is not necessary for the Precompiled Header to be used... All the headers that you want to precompile should be included by stdafx.h. Then, provided the files have inclusion guards, it won't be a problem when they are included again in the sources.

Example

Generated a.cpp file:

#include <a.h>
#include <b.h>
//rest of the code

Suppose you want to pre-compile a.h and b.h. Then you create the file stdafx.h:

#include <a.h>
#include <b.h>

And then you use the /FI option to have this stdafx.h included as the first file into a.cpp. If the files a.h and b.h have include guards, leaving them in a.cpp is not an issue...

小瓶盖 2024-08-15 02:36:19

“stdafx.h”只是一个约定。如果您知道生成的源文件始终具有包含标头的标准前缀,则可以在 /Yu 开关中命名最后一个标头(使用预编译标头)。要创建 PCH,请创建一个仅包含这些固定标头的 .cpp 文件,并使用 /Yc 进行编译。

"stdafx.h" is merely a convention. If you know that yout generated source files always have a standard prefix of included headers, you can name the last of them in the /Yu switch (use precompiled headers). To create the PCH, create an single .cpp file with just those fixed headers and compile ith with /Yc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文