You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何不安装Visual Studio安装MSVC编译器用于VS Code C++开发?

解决方法
  • 可以不安装完整Visual Studio,单独通过Visual Studio Build Tools安装MSVC编译器,这是微软官方提供的轻量工具集。
  • 具体操作步骤:
    1. 下载Visual Studio Build Tools安装程序,运行后在工作负载中勾选**“C++生成工具”**,务必确保包含以下核心组件:
      • MSVC vxxx - VS 20xx C++ x64/x86生成工具(根据你的系统架构选择对应版本)
      • 对应版本的Windows SDK(如Windows 11 SDK)
      • 若需CMake支持,可勾选C++ CMake工具 for Windows
    2. 完成安装后重启VS Code,此时打开命令面板(Ctrl+Shift+P)输入C/C++: Select a Configuration,应该就能正常选择MSVC编译器选项了。
  • 如果仍无法自动识别,可手动配置VS Code的编译配置文件:
    1. 在.vscode/tasks.json中添加MSVC编译任务示例:
      {
          "version": "2.0.0",
          "tasks": [
              {
                  "label": "msvc build",
                  "type": "shell",
                  "command": "cl.exe /EHsc main.cpp",
                  "group": {
                      "kind": "build",
                      "isDefault": true
                  },
                  "problemMatcher": "$msCompile"
              }
          ]
      }
      
    2. 在.vscode/c_cpp_properties.json中指定编译器路径与头文件目录示例:
      {
          "configurations": [
              {
                  "name": "Win32",
                  "includePath": [
                      "${workspaceFolder}/**",
                      "C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.36.32532/include"
                  ],
                  "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
                  "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe",
                  "cStandard": "c17",
                  "cppStandard": "c++17",
                  "intelliSenseMode": "windows-msvc-x64"
              }
          ],
          "version": 4
      }
      
    注意:上述路径中的版本号(如14.36.32532)需根据你实际安装的Build Tools版本调整。

内容的提问来源于stack exchange,提问作者ng.newbie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 00:37:20