在预编译头文件中包含resource.h是个好主意吗? [英] Is including resource.h in precompiled header a good idea?

查看:178
本文介绍了在预编译头文件中包含resource.h是个好主意吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VS-IDE将//{{NO_DEPENDENCIES}}写入资源头文件. 此注释实际上是一项功能,可以防止(不必要)重建包含资源头的cpp文件.

The VS-IDE will write //{{NO_DEPENDENCIES}} to resource header files. This comment is actually a feature that prevents (unnecessary) rebuilding of cpp files that include the resource header.

但是,就像MSDN中所述的 一样,这可能导致产生不良副作用".

But, like stated in the MSDN, this can lead to "undesirable side-effects".

在我们的项目中,我们确实将resource.h包含在stdafx.h中以进行预编译.不幸的是,如果资源文件发生更改,则无法重新编译预编译的头文件.

In our project we do have the resource.h included in the stdafx.h for pre-compilation. Unfortunately the precompiled header is not rebuild, if the resource file changes...

如果删除了NO_DEPENDENCIES,它将起作用(但如果通过IDE更改了资源,则会再次写入).

If the NO_DEPENDENCIES is removed, it works (but it's written again, if resources are changed via IDE).

是否有一种方法可以防止IDE在每次更改文件时将//{{NO_DEPENDENCIES}}写入resource.h文件?

Is there a way to prevent the IDE from writing //{{NO_DEPENDENCIES}} to the resource.h file every time the file was changed?

我认为最好的方法是将resource.h从预编译的头文件中排除,然后将它们重新包含在所需的.h和.cpp文件中.这样,只需(手动!)就可以重建受影响的文件,而不必重建所有文件(如果重新编译pch,则会发生这种情况).

I think the best way would be to exclude the resource.h from the precompiled header file and re-include them in the needed .h and .cpp files. This way only the affected files would need to be (manually!) rebuild and not all files (which would happen, if the pch is recompiled).

有任何评论吗?

推荐答案

我同意您的建议:resource.h文件可能不应该是预编译头文件的一部分.

I agree with your own suggestion: the resource.h file should probably not be part of the precompiled header file.

请注意,如果应用此建议导致编译时间过长,则可以尝试使用两个预编译的头文件:您当前使用的是一个,而您当前使用的是一个 with resource.h对方.后一个PCH仅由需要resource.h的文件使用.

Note that if applying this suggestion leads to too large compilation times, you could try to use two precompiled header files: your current one on one side, and your current one with resource.h on the other side. This latter PCH would be used only by the files that need resource.h.

虽然可能不太容易维护...

Proably not too easy to maintain, though...

这篇关于在预编译头文件中包含resource.h是个好主意吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆