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

VSCode配置MSVC时头文件路径报错求助:'crtdbg.h'未找到

解决VSCode配置MSVC时找不到crtdbg.h的问题

问题分析

crtdbg.h属于Windows SDK的调试组件,出现找不到的错误通常是因为:

  • Windows SDK的调试工具未安装
  • VSCode未正确加载MSVC和Windows SDK的环境变量
  • C++配置文件中缺少必要的头文件路径

具体解决方案

1. 补全Windows SDK调试组件

  • 打开Visual Studio Installer,找到已安装的「Visual Studio 2022 Build Tools」,点击「修改」
  • 在「工作负载」标签确认「C++生成工具」已勾选,切换到「单个组件」标签:
    • 搜索并勾选对应版本的Windows 10 SDK(需与你安装的版本匹配)
    • 搜索并勾选Windows SDK调试工具
  • 点击「修改」完成安装,等待组件更新完毕

2. 用Developer Command Prompt启动VSCode

直接打开VSCode会导致环境变量未加载MSVC和SDK路径,正确操作:

  • 开始菜单搜索「Developer Command Prompt for VS 2022」并打开
  • 在命令行输入 code 回车,启动VSCode

3. 修正C++配置文件(c_cpp_properties.json)

  • 按 Ctrl+Shift+P,输入「C/C++: Edit Configurations (JSON)」打开配置文件
  • 更新includePath、compilerPath和intelliSenseMode为你的实际路径(替换SDK版本号为你安装的版本):
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.38.33130/include",
                "C:/Program Files (x86)/Windows Kits/10/Include/10.0.xxxx.x/ucrt",
                "C:/Program Files (x86)/Windows Kits/10/Include/10.0.xxxx.x/shared",
                "C:/Program Files (x86)/Windows Kits/10/Include/10.0.xxxx.x/um"
            ],
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.38.33130/bin/Hostx64/x64/cl.exe",
            "intelliSenseMode": "windows-msvc-x64",
            "cppStandard": "c++17"
        }
    ],
    "version": 4
}
  • 可在Developer Command Prompt中输入以下命令获取SDK路径信息:
    echo %WindowsSdkDir%
    echo %WindowsSdkVersion%
    

4. 配置clang-tidy路径参数

  • 打开VSCode设置(Ctrl+,),搜索「C_Cpp.clangTidy.args」,点击「编辑 in settings.json」
  • 添加头文件包含参数,示例:
"C_Cpp.clangTidy.args": [
    "--header-filter=.*",
    "-I=C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/14.38.33130/include",
    "-I=C:/Program Files (x86)/Windows Kits/10/Include/10.0.xxxx.x/ucrt"
]

5. 验证修复

  • 重启VSCode,打开你的Hello World项目
  • 触发clang-tidy检查(可通过保存文件或手动执行「C/C++: Run Code Analysis」)
  • 尝试编译运行,确认无头文件错误

内容的提问来源于stack exchange,提问作者Codrineye

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 17:03:31