在 Windows (MSVC) 上为 C++ 设置 VSCode [英] Setup VSCode for C++ on Windows (MSVC)

查看:36
本文介绍了在 Windows (MSVC) 上为 C++ 设置 VSCode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

接下来我需要做什么?

如今,Intellisense 开箱即用,这很棒.但是我自动生成的 tasks.json 似乎并没有完成构建的技巧,它看起来像这样:

<代码>{//参见 https://go.microsoft.com/fwlink/?LinkId=733558//有关tasks.json 格式的文档"版本": "2.0.0",任务": [{"taskName": "构建",类型":过程",命令":msbuild",参数":[//要求 msbuild 生成文件名的完整路径."/property:GenerateFullPaths=true","/t:build"],"组": "构建",介绍": {//仅在发生无法识别的错误时才显示输出.揭示":总是"},//使用标准的 MS 编译器模式来检测错误、警告和信息"problemMatcher": "$msCompile"}]}

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

 执行任务:msbuild/property:GenerateFullPaths=true/t:build <

有什么想法吗?

解决方案

对于 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编译.

I'm a little befuddled that I'm not able to setup Visual Studio Code to do C++ development on Windows using MSVC. All over the web people say how pleased they are with how easy everything is to set up and use, but I don't find any straightforward guides; most of them just skip the setup part and show how nice everything works including code completion/intellisense and debugging support.

I have installed Visual Studio 2015 Community Edition (including the debugging tools etc.), Visual Studio Code and the C++ extension by Microsoft.

What do I need to do next?

Edit: Intellisense works out of the box these days, that's great. But my auto-generated tasks.json doesn't seem to do the trick for building, here's what it looks like:

{
    // 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"
        }
    ]
}

When I run this task it seems to run infinitely and only outputs to the following:

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

Any ideas?

解决方案

For MSVC 2017 version:

  1. add these to your include path:

"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",

You may change the drive name and folder name accordingly.

2.change your shell setting in settings.json:

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

which will enable the cl command in your integrated terminal.

3.Press ctrl+` to enable integrated terminal, type cl /EHsc your_cpp_program.cpp to compile.

这篇关于在 Windows (MSVC) 上为 C++ 设置 VSCode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆