MSVC 环境变量未显示在不同的终端中

MSVC environment variables not showing up in different terminals

本文关键字:终端 环境变量 显示 MSVC      更新时间:2023-10-16

我正在使用Haxe的HXCPP生成C++代码并使用Visual Studio 2010 Express Edition Microsoft编译它。我正在遵循本指南,它要求您运行"c:Program Files (x86)Microsoft Visual Studio 10.0Common7Toolsvsvars32.bat"以便cl.exe(编译器)在您的构建路径中。

确实允许我运行 cl.exe,但只能在该终端中运行。如果我尝试从另一个终端或在我的 IDE 中运行它,它会失败(崇高文本 2)。

我想出了一个解决方法:手动将变量值从终端复制+粘贴到 GUI 环境变量编辑器。

一定有更好的方法。我错过了什么?

构建.hxml

-main Test
-cpp bin

测试.hx

class Test {
    static function main() {
        trace("Hello World!");
    }
}

构建时出现错误消息

link.exe -out:Test.exe -nologo -machine:x86 -libpath:lib user32.lib -libpath:e:/VS8/PlatformSDK/Lib @all_objs
LINK : fatal error LNK1181: cannot open input file 'user32.lib'
Called from ? line 1
Called from BuildTool.hx line 1246
Called from BuildTool.hx line 554
Called from BuildTool.hx line 591
Called from BuildTool.hx line 710
Called from BuildTool.hx line 796
Called from BuildTool.hx line 285

您必须为已打开的每个终端(环境)运行以下命令:

c:Program Files (x86)Microsoft Visual Studio 10.0Common7Toolsvsvars32.bat

它定义的环境变量都是局部的。