Visual Studio 2010:使用define宏指定输出可执行文件
Visual Studio 2010: Using define macro to specify output executable
我需要使用在头文件中定义的#define宏,以便在输出文件的规范中使用。
为了指定我需要的内容,有一个带有#define VERSION 12条目的header.hpp文件,并希望输出myProgram_12.exe。有没有一种方法可以在Visual Studio 2010中实现这一点,而无需手动更改项目属性。
如果版本号的权威信息来源是#define
,那么恐怕没有简单的解决方案,但可以用一个丑陋的变通方法来完成。
您可以创建一个工具,从标题中提取版本号,并将其写入Visual Studio属性表(.vsprops
)文件,该文件将包含在您的项目中(在Property Manager
中)。该工具实际上可以是一个C++程序,它将#include
作为标头(或者至少启动这样一个程序来获得数字)。
当然,该工具可能应该缓存值,并且只在值不同时重新写入属性表,这样当您将该工具挂接到构建链中时,就不会得到不断的重建。
我可以建议您使用以下代码,在.h文件中
#define VERSION2
在.cpp文件中
' add reference to Microsoft.VisualStudio.VCProjectEngine
Imports EnvDTE
Imports Microsoft.VisualStudio.VCProjectEngine
Public Module Module1
Sub Test()
Dim prj As VCProject
Dim cfgs, tools As IVCCollection
Dim cfg As VCConfiguration
Dim tool As VCLinkerTool
prj = DTE.Solution.Projects.Item(1).Object
cfgs = prj.Configurations
cfg = cfgs.Item(1)
tool = cfg.Tools("VCLinkerTool")
#ifdef VERSION2
tool.OutputFile = "$(ProjectName).exe"
#ifdef VERSION3
tool.OutputFile = "$(ProjectName1).exe"
End Sub
End Module
它的VB代码,但您可以使用此链接轻松地将其转换为VC++代码如何:为项目模型扩展性编译示例代码
相关文章:
- 如何将不同的可执行文件合并到一个窗口框架中进行编码?像浏览器一样
- 如何使 windows 命令提示符在C++可执行文件上显示返回值?
- CMake:如何将库 A 链接到库 B,然后将可执行文件链接到库 A
- 如何使字符串出现在编译的二进制可执行文件的开头?
- 程序在使用 system() 启动另一个可执行文件时停止
- 如何更改使用 CPack 安装的可执行文件的名称?
- 如何将图像传入C++可执行文件并将输出图像存储在新目录中?
- 将我的主输出库与测试可执行文件链接时出现问题
- 获取生成文件以更改输出可执行文件名称
- 如何从控制台启动可执行文件并使用Qt读取输出
- GCC 8 交叉编译器输出 ARMv7 可执行文件而不是 ARMv6
- C++ 在代码中更改输出可执行文件名称
- 启动/运行外部可执行文件并查看其输出日志
- "make"的输出是一个共享对象,而不是可执行文件
- 'Continuous' C++一个可执行文件的输出作为另一个程序的输入
- 从 Java 运行可执行文件时C++没有错误或输出
- 输入/输出从命令行可执行文件重定向到文件
- Visual Studio 2010:使用define宏指定输出可执行文件
- Borland c++ Builder 6调整输出可执行文件大小,以适应屏幕
- 用 c++ 包装可执行文件的输入和输出