【问题标题】:Setup VSCode for C++ on Windows (MSVC)在 Windows (MSVC) 上为 C++ 设置 VSCode
【发布时间】:2018-04-17 08:28:12
【问题描述】:

我有点困惑,我无法设置 Visual Studio Code 以使用 MSVC 在 Windows 上进行 C++ 开发。在整个网络上,人们都说他们对设置和使用一切的简单性感到非常高兴,但我找不到任何简单的指南;他们中的大多数只是跳过了设置部分,并展示了包括代码完成/智能感知和调试支持在内的一切工作如何。

我已经安装了 Visual Studio 2015 Community Edition(包括调试工具等)、Visual Studio Code 和微软的 C++ 扩展。

接下来我需要做什么?

编辑: 如今,Intellisense 开箱即用,这很棒。但是我的自动生成的 tasks.json 似乎并没有起到构建的作用,它看起来是这样的:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "build",
            "type": "process",
            "command": "msbuild",
            "args": [
                // Ask msbuild to generate full paths for file names.
                "/property:GenerateFullPaths=true",
                "/t:build"
            ],
            "group": "build",
            "presentation": {
                // Reveal the output only if unrecognized errors occur.
                "reveal": "always"
            },
            // Use the standard MS compiler pattern to detect errors, warnings and infos
            "problemMatcher": "$msCompile"
        }
    ]
}

当我运行这个任务时,它似乎无限运行并且只输出到以下内容:

 Executing task: msbuild /property:GenerateFullPaths=true /t:build <

有什么想法吗?

【问题讨论】:

  • 开始输入代码?

标签: c++ visual-studio-code


【解决方案1】:

对于 MSVC 2017 版本:

  1. 将这些添加到您的包含路径中:

"D:/Program Files/Microsoft/MSVC2017/VC/Tools/MSVC/14.12.25827/include/*",

“C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt”,

“C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10240.0/ucrt/x64”,

您可以相应地更改驱动器名称和文件夹名称。

2.在 settings.json 中更改你的 shell 设置:

"terminal.integrated.shell.windows": "C:\WINDOWS\System32\cmd.exe", "terminal.integrated.shellArgs.windows": ["/k", "D:/Program Files/Microsoft/MSVC2017/Common7/Tools/VsDevCmd.bat"]

这将在您的集成终端中启用 cl 命令。

3.按ctrl+`开启集成终端,输入cl /EHsc your_cpp_program.cpp编译。

【讨论】:

    【解决方案2】:

    我认为获取它的最简单方法 - 打开 Visual Studio 2017 命令提示符控制台并从那里运行 Visual Studio Code IDE,这样它将选择所有必要的编译器环境变量

    【讨论】:

      猜你喜欢
      • 2021-10-28
      • 1970-01-01
      • 2020-06-02
      • 2022-09-27
      • 1970-01-01
      • 1970-01-01
      • 2021-03-14
      • 2017-07-31
      • 2020-06-18
      相关资源
      最近更新 更多