在预构建事件中设置环境变量并在编译步骤中使用 [英] Setting environment variables in pre-build event and using in compilation step

查看:375
本文介绍了在预构建事件中设置环境变量并在编译步骤中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio 2003中,我试图在预构建事件中设置一个环境变量,然后在编译步骤中使用该环境变量,但是该值似乎没有被传播。例如,如果预构建事件包含此(直接或在批处理文件中):

In Visual Studio 2003, I am trying to set an environment variable in the pre-build event that will then be used in the compilation step, but the value doesn't seem to be propagated. For example, if the pre-build event contains this (either directly or within a batch file):

set MY_LIB_VERSION=1.0.0

和AdditionalIncludeDirectories具有:

and AdditionalIncludeDirectories has this:

c:\path\to\library\my_lib_v$(MY_LIB_VERSION)\include

那么如果 my_lib_v1.0.0 目录存在,我期望编译工作。但是,我得到

then I would expect the compilation to work if the my_lib_v1.0.0 directory exists. But instead, I get


c:\path\to\prog\my_prog.c(22) : fatal error C1083: Cannot open include file: 'my_lib.h'
Project : warning PRJ0018 : The following environment variables were not found:
$(MY_LIB_VERSION)

我推断在预构建事件中设置的环境变量因此没有传播到编译步骤,但是我可能会缺少一些东西。

I deduce that the environment variable set in the pre-build event therefore isn't being propagated to the compilation step, but I may be missing something.

如何在预构建事件中设置环境变量并在编译步骤中使用它?

其他明确的方式定义一个库版本一次,并使用它几次为AdditionalIncludeDirectories和AdditionalLibraryDirectories也会做得很好。)

(Alternatively, any other sensible ways of defining a library version once and using it several times for AdditionalIncludeDirectories and AdditionalLibraryDirectories would do just as well.)

更新:我最终以不同的方式解决了我们的问题。我们使用Subversion,并在项目源的名为 dependencies 的子目录中设置 svn:externals 项目的检出将另外检出< svn_path> \libraries\my_lib_v1.0.0 并调用它 dependencies\my_lib 在工作副本。然后项目设置可以参考 dependencies\my_lib\include 等。升级到版本1.0.1的 my_lib 只是一个问题编辑 svn:externals 属性 - 代码

Update: I ended up solving our problem in a different way. We are using Subversion, and set up the svn:externals property on a subdirectory of the project source called dependencies, such that a checkout of the project would additionally check out <svn_path>\libraries\my_lib_v1.0.0 and call it dependencies\my_lib in the working copy. Then the project settings could refer to dependencies\my_lib\include and suchlike. Upgrading to version 1.0.1 of my_lib is then simply a matter of editing the svn:externals property -- the code and project settings did not need to change.

推荐答案

您可能需要调查此工具: http://workspacewhiz.com/SolutionBuildEnvironmentReadme.html

You might want to investigate this tool: http://workspacewhiz.com/SolutionBuildEnvironmentReadme.html

我们全部使用在构建环境中管理环境变量的时间。

We use it all the time to manage environment variables in our build environment.

这篇关于在预构建事件中设置环境变量并在编译步骤中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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