从Visual C ++中的文件内容设置预处理器定义 [英] Set preprocessor definitions from file content in Visual C++

查看:232
本文介绍了从Visual C ++中的文件内容设置预处理器定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一个文件,其中包含项目的版本号.我必须在代码中将此文件的内容作为预处理器定义提供.

I have a file in my project which contains the project version number. I have to make the content of this file available as a preprocessor definition in my code.

我需要以某种方式将文件中的值作为/D参数传递给编译器.

What I need is to somehow pass the value from the file to the compiler as a /D parameter.

我试图添加预处理器定义

I tried to add the preprocessor definition

VERSION=$(Version)

并在预构建步骤中设置Version环境变量,但是我没有找到执行后者的方法,所以我被卡住了.

and set the Version environment variable in a prebuild step, but I did not find a way to do the latter, so I got stuck.

推荐答案

作为一种解决方法,可以创建一个预构建步骤,该步骤将调用一个脚本来读取文件并在标头中生成宏定义.然后可以将此头文件包含在我的项目中.

As a workaround, a pre-build step could be created which calls a script that reads the file and generates the macro definition in a header. Then this header file could be included in my projects.

但是,我觉得这个解决方案不好,我希望有一个更好的解决方案.

However I do not find this solution nice, I hope there is a better one.

这篇关于从Visual C ++中的文件内容设置预处理器定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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