C++ Visual Studio 2013 中的环境变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20455041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Environment variables in Visual Studio 2013
提问by LCartwright
I'm trying to set my project include to the path %OPENCV_246%\..\..\include
我正在尝试将我的项目包含到路径中 %OPENCV_246%\..\..\include
This resolves to the path F:\dev\opencv_246\build\include
这解析为路径 F:\dev\opencv_246\build\include
However, when setting the project includes, that path will not resolve and as a result the included headers break.
但是,在设置项目包含时,该路径将无法解析,因此包含的标题会中断。
I've tried both %OPENCV_246%\..\..\include
and $(OPENCV_246)\..\..\include
with no luck.
我都试过%OPENCV_246%\..\..\include
,并$(OPENCV_246)\..\..\include
没有运气。
Using the path directly fixes my includes, but I'd like to have a better way of managing the path through environment variables.
使用路径直接修复我的包含,但我想有一个更好的方法通过环境变量管理路径。
In the screenshot I've added both for clarity, If anyone could point out the step I'm missing here I'd appreciate it.
在屏幕截图中,为了清楚起见,我添加了两者,如果有人能指出我在这里遗漏的步骤,我将不胜感激。
EDIT: Variable OPENCV_246
contains value F:\dev\opencv_246\build\x86\vc11
编辑:变量OPENCV_246
包含值F:\dev\opencv_246\build\x86\vc11
回答by NickD
Dev studio won't recognize any environment variables that have been changed since it was started, so if you change one, a restart is required (of Dev studio, not the computer).
Dev Studio 不会识别自启动以来已更改的任何环境变量,因此如果您更改一个,则需要重新启动(Dev Studio,而不是计算机)。
https://superuser.com/questions/107521/why-are-changes-to-my-path-not-being-recognised
https://superuser.com/questions/107521/why-are-changes-to-my-path-not-being-recognised
回答by Timothy Pitt
This sounded similar to my problem, which was getting VS2013 to acknowledge a change I made to my environment variable (in my case QTDIR). Even after a restart and a shutdown, it obstinately hung on to the old value !! (you can see the value if you go to edit a project setting, hit the "Macros" button, and scroll down the list to find e.g. "$(QTDIR)" )
这听起来与我的问题相似,即让 VS2013 确认我对环境变量(在我的情况下为 QTDIR)所做的更改。即使在重新启动和关闭后,它仍然顽固地挂在旧值上!!(如果您去编辑项目设置,点击“宏”按钮,然后向下滚动列表以查找例如“$(QTDIR)”,您可以看到该值)
Hereit suggest VS2010 cahed values heavily, but 2013 seems even more keen !
这里建议 VS2010 大量缓存值,但 2013 似乎更加敏锐!
After some FindInFiles for the old path, it seems that VS2013 caches environment variables in your .vcxproj.user file. I have no idea how it got in there in the first place.
在旧路径的一些 FindInFiles 之后,VS2013 似乎在您的 .vcxproj.user 文件中缓存了环境变量。我不知道它最初是如何进入那里的。
So I deleted the entry, closed the solution, checked the file again in WordPad to make sure the entry hadn't been put back in. Then I re-opened the solution, but the old value was stillthere in the Macros list !
所以我删除了条目,关闭了解决方案,再次在写字板中检查了文件以确保条目没有被放回。然后我重新打开了解决方案,但旧值仍然存在于宏列表中!
Closing VS seems to have done the trick. Now it seems to have the right path - although I'm sure I checked after I first opened the solution and QTDIR wasn't in the Macros list at all - maybe I'm confused...
关闭 VS 似乎成功了。现在它似乎有正确的路径 - 尽管我确定我在第一次打开解决方案后检查过并且 QTDIR 根本不在宏列表中 - 也许我很困惑......
Well, it all seems to be working now, and my project builds and links to my Qt libs without complaints :-)
好吧,现在似乎一切正常,我的项目构建并链接到我的 Qt 库,没有任何抱怨:-)
And, the entry in the vcxproj.user file hasn't come back. So I still don't know how it got in there. Maybe I did something to cause it a while back in a previous version of VS...
而且,vcxproj.user 文件中的条目还没有回来。所以我还是不知道它是怎么进来的。也许我在以前版本的 VS 中做了一些事情导致它......