【问题标题】:How to make visual studio code run vcvarsx86_arm64.bat instead of vcvarsall.bat directly?如何让 Visual Studio 代码直接运行 vcvarsx86_arm64.bat 而不是 vcvarsall.bat?
【发布时间】:2019-11-23 21:34:53
【问题描述】:

我试图使用 VSC 使用 MSVC 构建我的 c++ 程序。我曾经通过执行 vcvarsx86_arm64.bat 然后使用命令来做到这一点。

cl /EHsc /Z7 /W4 /Fe: ${fileDirname}.exe *.cpp

这很好用。但我确实想尝试以 VSC 的方式来做。 我检查了 Microsoft 文档并构建了 c_cpp_properties,如下所示。

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.18362.0",
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/bin/Hostx64/x64/cl.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "msvc-x64"
        }
    ],
    "version": 4
}

我正在使用以下构建任务进行测试:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "cl.exe build active file",
            "command": "echo hi",
            "group": "build"
        }
    ]
}

这是我收到的错误消息

> Executing task: echo hi <

[ERROR:vcvarsall.bat] Invalid argument found : /d
[ERROR:vcvarsall.bat] Invalid argument found : /c
[ERROR:vcvarsall.bat] Invalid argument found : echo
[ERROR:vcvarsall.bat] Invalid argument found : hi
[ERROR:vcvarsall.bat] Error in script usage. The correct usage is:
Syntax:
    vcvarsall.bat [arch] [platform_type] [winsdk_version] [-vcvars_ver=vc_version] [-vcvars_spectre_libs=spectre_mode]
where :
    [arch]: x86 | amd64 | x86_amd64 | x86_arm | x86_arm64 | amd64_x86 | amd64_arm | amd64_arm64     
    [platform_type]: {empty} | store | uwp
    [winsdk_version] : full Windows 10 SDK number (e.g. 10.0.10240.0) or "8.1" to use the Windows 8.1 SDK.
    [vc_version] : {none} for latest installed VC++ compiler toolset |
                   "14.0" for VC++ 2015 Compiler Toolset |
                   "14.xx" for the latest 14.xx.yyyyy toolset installed (e.g. "14.11") |
                   "14.xx.yyyyy" for a specific full version number (e.g. "14.11.25503")
    [spectre_mode] : {none} for libraries without spectre mitigations |
                     "spectre" for libraries with spectre mitigations

The store parameter sets environment variables to support Universal Windows Platform application
development and is an alias for 'uwp'.

For example:
    vcvarsall.bat x86_amd64
    vcvarsall.bat x86_amd64 10.0.10240.0
    vcvarsall.bat x86_arm uwp 10.0.10240.0
    vcvarsall.bat x86_arm onecore 10.0.10240.0 -vcvars_ver=14.0
    vcvarsall.bat x64 8.1
    vcvarsall.bat x64 store 8.1

Please make sure either Visual Studio or C++ Build SKU is installed.

当我直接调用 vcvarsall.bat 时,我看到了相同的错误消息。所以我认为 vcvarsall.bat 在某处被调用。但我不知道如何解决它。我做了一些研究,但没有发现任何东西。

【问题讨论】:

    标签: c++ batch-file visual-studio-code vscode-tasks


    【解决方案1】:

    我最近偶然发现了这个问题的一个类似变体,我发现绕过它的唯一方法是在 tasks.json 上配置 shell 选项。像这样:

    {
        "version": "2.0.0",
        "windows": {
            "options": {
                "shell": {
                    "executable": "cmd.exe",
                    "args": [
                        "/d", "/c", "Your\\Path\\To\\vcvarsx86_arm64.bat", "&" 
                    ]
                }
            }
        },
        "tasks": [
            {
                "label": "Build",
                "type": "shell",
                "command": "echo write your build command here"
            }
        ]
    }
    

    【讨论】:

      【解决方案2】:

      我想补充一下上面 Ikeike 的回答,如果您不想覆盖用于文件中所有任务的 shell,您可以调整该方法以仅调用 cmd.exe 从您的当前的外壳(在我的情况下,Powershell)。例如,我的任务如下所示:

          "label": "Configure (CMake, Ninja)",
          "type": "shell",
          "options":
          {
              "cwd": "${workspaceFolder}\\build"
          },
          "command": "cmd.exe",
          "args":
          [
              "/d",
              "/c",
              "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\VC\\Auxiliary\\Build\\vcvars64.bat",
              "'&'",
              "cmake",
              "-G", "Ninja",
              ".."
          ]
      }
      

      Powershell 要求我引用 &amp;,但其余部分很简单。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-09-21
        • 1970-01-01
        • 2015-09-04
        • 1970-01-01
        • 1970-01-01
        • 2020-03-28
        • 2016-01-21
        • 1970-01-01
        相关资源
        最近更新 更多