如何有条件编译VC6资源
根据以环境变量的形式设置的编译开关(值为 COMPILE_A
或 COMPILE_B
),我想使用不同的设置来编译我的应用程序,例如 application名称和启动屏幕。
我到目前为止:
在“Project / Settings / C/C++ / Preprocessor Definitions”中我添加了
$(COMPILESWITCH)
(结果是命令行选项/D "$(COMPILESWITCH) ”
)。在stdafx.h中我可以使用以下代码,这意味着我通过命令行参数正确定义了预处理器定义:
#if defined COMPILE_A
# define IDB_SPLASH IDB_SPLASH_A
# elif defined COMPILE_B
# define IDB_SPLASH IDB_SPLASH_B
# else
# error Unknown or undefined target compile switch; cannot compile!
# endif
但我注意到“ResourceView / [右键] / Properties”下的“Condition”属性... 帮助文本是这样说的:
健康)状况确定包含 资源。 例如,如果 条件是_DEBUG,这个资源 仅包含在调试中 构建。
这看起来是一种优雅的做法,对吧?
指定 _DEBUG
作为条件有效。 因此,由于 _DEBUG
是通过 /D _DEBUG
指定的,所以我的 $(COMPILESWITCH)
也应该可以工作,对吗?
由于某种原因,事实并非如此; 为什么?
或者还有其他更好的方法来实现我想要的吗?
depending on a compile switch (values are COMPILE_A
or COMPILE_B
), which is set in the form of an envorinment variable, I want to compile my application with different settings, like application name and splash screen.
I got this far:
In "Project / Settings / C/C++ / Preprocessor Definitions" I added
$(COMPILESWITCH)
(results in command line option/D "$(COMPILESWITCH)"
).In stdafx.h I can use the following code, which means I correctly defined the preprocessor definition via the command line parameter:
#if defined COMPILE_A
# define IDB_SPLASH IDB_SPLASH_A
# elif defined COMPILE_B
# define IDB_SPLASH IDB_SPLASH_B
# else
# error Unknown or undefined target compile switch; cannot compile!
# endif
But I've noticed the "Condition" property under "ResourceView / [right-click] / Properties"...
The help text says this:
Condition
Determines the inclusion of
the resource. For example, if the
condition is _DEBUG, this resource
would be included only in debug
builds.
This looks like the elegant way of doing it, right?
Specifiying _DEBUG
as condition works. So as _DEBUG
is specified via /D _DEBUG
my $(COMPILESWITCH)
should also work, right?
For some reason it doesn't; why?
Or is there even another, better way to achieve what I want?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我刚刚解决了我的问题...
资源编译器使用它自己的预处理器。
因此,必须在“项目/设置/资源/预处理器定义”下添加相同的预处理器定义。
编辑:字符串资源
上述不适用于字符串资源,因为它们没有“条件”属性...
我选择使用
res\.rc2
自定义资源文件资源编辑器不会触及它。内容看起来像这样
I guess I just solved my problem...
The resource compiler uses its own preprocessor.
Therefore the same preprocessor definition has to be added under "Project / Settings / Resources / Preprocessor Definitions".
Edit: String Resources
The above doesn't work for string resources as they don't have a "condition" property...
I chose to use the
res\<projectname>.rc2
custom resource file which won't be touched by the resource editor.The content looks like this