无法识别 Visual Studio 代码任务构建“C:\Program”

2023-11-30

因此,我使用 Visual Studio Code 来构建并运行一个简单的 C++ 程序。我使用tasks.json来处理编译:(基于此:如何使用 VS Code 和 cl 编译 C++ 代码

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build Test",
            "type": "shell",
            "command": "cl",
            "args": [
                "/MDd",
                "/W4",
                "/EHsc",
                "/ZI",
                "/std:c++11",
                "/Od",
                "/Fe:${workspaceFolder}/Debug/test.exe",
                "/Fd:${workspaceFolder}/Debug/",
                "/Fo:${workspaceFolder}/Debug/",
                "main.cpp"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "Build Release",
            "type": "shell",
            "command": "cl",
            "args": [
                "/MD",
                "/W4",
                "/EHsc",
                "/std:c++11",
                "/O2",
                "/Fe:${workspaceFolder}/Release/test.exe",
                "/Fd:${workspaceFolder}/Release/",
                "/Fo:${workspaceFolder}/Release/",
                "main.cpp"
            ]
        }
    ]
}

但是当我尝试构建时,我得到以下输出:

 Executing task: cl /MDd /W4 /EHsc /ZI /std:c++11 /Od "/Fe:G:\My Drive\Semester 3\CS 341\Project\Project 2/Debug/test.exe" "/Fd:G:\My Drive\Semester 3\CS 341\Project\Project 2/Debug/" "/Fo:G:\My Drive\Semester 3\CS 341\Project\Project 2/Debug/" main.cpp <

'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

我会注意到,我确实通过以下方式更改了设置:

"terminal.integrated.shellArgs.windows": [
        "/k",
        "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat"
    ],
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe"

我相信这就是“C:\Program”的来源。 我只想在 Visual Studio 中构建和执行 C++ 程序,因此我们将不胜感激。

EDIT:所以我决定添加C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build到 PATH 变量,然后我将设置更改为:

"terminal.integrated.shellArgs.windows": [
        "/k",
        "vcvars64.bat",
    ],
 "terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe"

这导致错误变成:

> Executing task: cl /MDd /W4 /EHsc /ZI /std:c++11 /Od "/Fe:G:\My Drive\Semester 3\CS 341\Project\Project 2/Debug/test.exe" "/Fd:G:\My Drive\Semester 3\CS 341\Project\Project 2/Debug/" "/Fo:G:\My Drive\Semester 3\CS 341\Project\Project 2/Debug/" main.cpp <

[ERROR:vcvarsall.bat] Invalid argument found : /d
[ERROR:vcvarsall.bat] Invalid argument found : /c
[ERROR:vcvarsall.bat] Invalid argument found : cl
[ERROR:vcvarsall.bat] Invalid argument found : /MDd
[ERROR:vcvarsall.bat] Invalid argument found : /W4
[ERROR:vcvarsall.bat] Invalid argument found : /EHsc
[ERROR:vcvarsall.bat] Invalid argument found : /ZI
[ERROR:vcvarsall.bat] Invalid argument found : /std:c++11
[ERROR:vcvarsall.bat] Invalid argument found : /Od
The syntax of the command is incorrect.

空格和括号的问题可以通过以下方式解决转义字符这是插入符号 (^) 在这种情况下。使用提到的字符在您的相关行settings.json看起来像:

"terminal.integrated.shellArgs.windows": [
    "/k",
    "C:\\Program^ Files^ ^(x86^)\\Microsoft^ Visual^ Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat"
],
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe"

这种方法的问题与您添加路径时遇到的问题相同vcvars64.bat to the PATH变量,即 Visual Studio Code 将append的价值观"command" and "args"从你的tasks.json前缀为/d and /c的值"terminal.integrated.shellArgs.windows"当执行你的任务时。这导致vcvars64.bat将得到提到的值作为参数而不是cmd.exe。标记为的错误[ERROR:vcvarsall.bat]出现的原因是拒绝参数附加到了错误的地方。

您可以通过为您的任务指定带有适当参数的 shell 来解决此问题,如下所示:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "options": {
        "shell": {
            "executable": "C:\\Windows\\System32\\cmd.exe",
            "args": [
                "/d", "/c",
                "C:\\Program^ Files^ ^(x86^)\\Microsoft^ Visual^ Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat",
                "&&"
            ]
        }
    },
    "tasks": [
        {
            "label": "Build Test",
            "type": "shell",
            "command": "cl",
            "args": [
                "/MDd",
                "/W4",
                "/EHsc",
                "/ZI",
                "/std:c++11",
                "/Od",
                "/Fe:${workspaceFolder}/Debug/test.exe",
                "/Fd:${workspaceFolder}/Debug/",
                "/Fo:${workspaceFolder}/Debug/",
                "main.cpp"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "Build Release",
            "type": "shell",
            "command": "cl",
            "args": [
                "/MD",
                "/W4",
                "/EHsc",
                "/std:c++11",
                "/O2",
                "/Fe:${workspaceFolder}/Release/test.exe",
                "/Fd:${workspaceFolder}/Release/",
                "/Fo:${workspaceFolder}/Release/",
                "main.cpp"
            ]
        }
    ]
}

另一种方法是离开"terminal.integrated.shellArgs.windows"空,即不向cmd.exe in the settings.json,然后改变你的tasks.json如下:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "options": {
        "env": {
            "build": "C:\\Program^ Files^ ^(x86^)\\Microsoft^ Visual^ Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvars64.bat && cl"
        }
    },
    "tasks": [
        {
            "label": "Build Test",
            "type": "shell",
            "command": "%build%",
            "args": [
                "/MDd",
                "/W4",
                "/EHsc",
                "/ZI",
                "/std:c++11",
                "/Od",
                "/Fe:${workspaceFolder}/Debug/test.exe",
                "/Fd:${workspaceFolder}/Debug/",
                "/Fo:${workspaceFolder}/Debug/",
                "main.cpp"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "Build Release",
            "type": "shell",
            "command": "%build%",
            "args": [
                "/MD",
                "/W4",
                "/EHsc",
                "/std:c++11",
                "/O2",
                "/Fe:${workspaceFolder}/Release/test.exe",
                "/Fd:${workspaceFolder}/Release/",
                "/Fo:${workspaceFolder}/Release/",
                "main.cpp"
            ]
        }
    ]
}

调用的必要性vcvars64.bat如果从 Visual Studio 的开发人员命令提示符启动 Visual Studio Code,则可以省略每个构建之前的内容。为了方便起见,您可以使用以下目标创建快捷方式:

cmd /d /c "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat" && start /b code

这将使开发人员命令提示符保持打开状态,可以根据需要关闭它。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法识别 Visual Studio 代码任务构建“C:\Program” 的相关文章

随机推荐

  • 多个 Mat Paginator 无法在 Angular 组件中工作

    我有三个不同的 div Post Todo User 根据用户选择我显示不同的表格 例如 默认情况下Post部分加载表100 records 如果用户选择Todo部分 表格应显示Todo记录等带有分页 I ve three datasour
  • R tableGrob 更改行的格式

    我有一些相对简单的代码来创建用于打印到 PDF 的表格 library gridExtra df lt head iris tableGrob df gp gpar fontsize 8 rows NULL 我想让最后一行的格式与标题行相同
  • 使用 Windows 批处理文件的单行多个命令

    我尝试了解批处理文件中单个命令行中的多个命令如何工作 dir md folder1 rename folder1 mainfolder 和其他具有类似命令的情况 但是 替换为 dir md folder1 rename folder1 ma
  • 为什么 Microsoft Azure(或一般的 Swift)无法更新变量以在表查询后返回?

    我一直在关注微软Azure文档成功查询表 将项目插入 读取和更新到数据库中工作正常 但在一个简单的方法结束时 立即关闭文档 func getAllEventIDs gt String var events String this is to
  • 基于 Django 类的 UpdateView 以及用于多个上传文件的表单

    针对我目前面临的问题 我有两个问题 django 中的最佳实践是覆盖 CreateView 中的 post 方法吗 如果不是 您是否在 CategoryFullForm 或 CreateView 中编写 form valid 函数 它会是什
  • 名称查找和类范围

    为什么setVal的返回类型是string类型 参数类型是double类型 typedef string Type Type initVal class Exercise public typedef double Type Type se
  • Ember renderTemplate 中继模型

    在这里努力开发我的 Ember 应用程序 一切进展顺利 但是 我遇到了意外行为的问题 并且不确定解决此问题的最佳方法 问题是在特定路线中 我想将另一条路线渲染到另一个出口 但是 我渲染到另一个出口的另一条路线并不保留它自己的模型 如果我这样
  • 如何在 Tensorflow 中将变量重用设置回 False?

    在Tensorflow中 我们可以将变量重用设置为True with tf get variable scope reuse variables 有什么方法可以在不离开范围的情况下将其设置回 False 吗 这不可能 在共享变量的教程中 他
  • 如何在 Linux 中转义 scp 复制路径中的空格?

    我想将文件从远程复制到本地系统 现在我在linux系统中使用scp命令 我有一些文件夹或文件名带有空格 当我尝试复制该文件时 它显示错误消息 没有这样的文件或目录 I tried scp email protected home 5105
  • Laravel 4 - 分页忽略 Fluent 中的不同

    我以清晰和分页的方式提出流畅的请求 我的问题是分页请求在不同的请求之前执行 我的流利要求 candidates DB table candidates gt select candidates gt distinct gt join can
  • 如何使 For-Each 循环向后运行

    我用 VBA 编写了一个小脚本 它根据列表检查给定范围内的单元格的值 如果单元格值与列表中的值匹配 则保留该单元格值 否则将其删除 我想知道如何让它向后运行 因为向前运行会产生问题 我对此进行了一些研究 并尝试将 Step 1 附加到开始
  • Matlab神经网络,如何强制使用某些集合进行训练、验证和测试?

    如果您使用 GUI nnstart 则仅提供输入和输出 但您无法决定哪些行将作为训练 验证和测试集 因为它们是随机选择的 如何手动指定它们 您可以使用从 NNSTART 启动的任何 GUI 来创建一些示例训练代码 然后通过设置以下数据划分值
  • 从 Base64 编码字符串中检索 ECC 公钥

    我一直在尝试创建一个实例java security PublicKey使用 Base64 编码的 ECC 公钥 MainActivity java Override protected void onCreate Bundle savedI
  • 生成的 SVG 图像不显示

    我正在开发一个 JavaScript 类来显示所有 SVG 对象 但是当我创建元素 image 时 浏览器不会显示它 但是 如果我复制生成的代码并将其放入另一个文档中 则会显示图像 当我使用 Firebug 的检查器搜索图像时 出现了对象但
  • EJB 3.1:是否允许将 Bean 注入到不受容器管理的资源中?

    我使用的是 JBoss 6 1 它不完全符合 EJB 3 1 截至目前 我无法通过以下方式将 EJB 注入到我的 Struts 操作类 或任何非 Java EE 容器管理的类中 EJB 但是当 EJB 3 1 规范完全实现时这可能吗 如果没
  • Spring Security 注销后退按钮

    spring security有办法防止下面最后一点吗 我用的是3 0 5 用户登录我的网站 用户转到网站中的任何页面并单击注销 注销链接使用户会话无效并将其发送到我网站的登录页面 在同一浏览器中 用户导航到新网站 例如 cnn com 用
  • 无法在android中的graph api中获取性别

    我无法在这里获取性别OnCompleted功能 我可以获得其他参数 例如id name email 目前应用程序处于开发模式 这是昨天工作的 Code GraphRequest request GraphRequest newMeReque
  • 使用“ADODB.Stream”将ANSI转换为UTF-8,第一行丢失1-2个字符

    我需要将 ANSI csv 文件转换为 UTF 8 csv 文件 下面的代码可以工作 但第一个字符丢失 请参阅随附的屏幕截图 原始文件 客户 输出文件 客户 Function Convert myFileIn myFileOut Dim s
  • JavaScript this 来自 jQuery this

    有没有办法从 jQuery this 获取 JavaScript this this this 任何this is this不是 jquery 而是一个特殊的 有些复杂的 javascript 关键字 用于描述当前的执行范围 您的挑战可能是
  • 无法识别 Visual Studio 代码任务构建“C:\Program”

    因此 我使用 Visual Studio Code 来构建并运行一个简单的 C 程序 我使用tasks json来处理编译 基于此 如何使用 VS Code 和 cl 编译 C 代码 See https go microsoft com f