vscode运行调试c++代码的配置文件

本文介绍了如何在VSCode中使用C++进行项目配置,包括c_cpp_properties.json中的编译设置,launch.json中的调试配置以及tasks.json中的构建任务,重点涉及mingw编译器和gdb调试器的路径设置。
摘要由CSDN通过智能技术生成

1.c_cpp_properties.json

{
    "configurations": [
        {
          "name": "Win32",
          "includePath": ["${workspaceFolder}/**"],
          "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
          "windowsSdkVersion": "10.0.17763.0",
          "compilerPath": "F:\\codeConfiguration\\minGW\\bin\\g++.exe",   /*修改成自己bin目录下的g++.exe,这里的路径和电脑里复制的文件目录有一点不一样,这里是两个反斜杠\\*/
          "cStandard": "c11",
          "cppStandard": "c++17",
          "intelliSenseMode": "${default}"
        }
      ],
      "version": 4
}

2.launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [

        {
            "name": "run",
            "preLaunchTask": "g++.exe build active file",//调试前执行的任务,就是之前配置的tasks.json中的label字段
            "type": "cppdbg",//配置类型,只能为cppdbg
            "request": "launch",//请求配置类型,可以为launch(启动)或attach(附加)
            "program": "E:\\code\\.vscode\\run.exe",//调试程序的路径名称
            "args": [],//调试传递参数
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,//true显示外置的控制台窗口,false显示内置终端
            "MIMode": "gdb",
            "miDebuggerPath": "E:\\mingw64_GCC8.1\\mingw64\\bin\\gdb.exe", //修改为自己的路径
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}


3.tasks.json

{
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "g++.exe build active file",
            "command": "E:\\mingw64_GCC8.1\\mingw64\\bin\\g++.exe", //修改为自己的路径
            "args": [
                "-g",
                "${file}",
                "-o",
                //"${fileDirname}\\${fileBasenameNoExtension}.exe"
                "E:\\code\\.vscode\\run.exe", //将exe文件统一放在这里
            ],
            "options": {
                "cwd": "E:\\mingw64_GCC8.1\\mingw64\\bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
				"kind": "build",
				"isDefault": true
			}

        }
    ]
}


在VS Code中调试C代码可以使用其内嵌的GDB图形化界面调试功能,这对于C/C++开发者来说非常方便。你可以按照以下步骤进行配置: 1. 确保你已经安装了GDB调试器。你可以在终端中运行`gdb --version`来检查是否已安装。 2. 在VS Code中安装C/C++插件,该插件提供了调试所需的功能。 3. 配置`.vscode/launch.json`文件,该文件用于配置调试器。你可以通过按下`Ctrl + Shift + P`打开命令面板,然后输入`C/Cpp: Generate Debug Configuration`来自动生成该文件。 4. 在生成的`launch.json`文件中,确保以下配置项正确设置: - `"name"`: 调试配置的名称。 - `"type"`: 调试器的类型,对于C/C++代码,设置为`"cppdbg"`。 - `"request"`: 设置为`"launch"`以启动调试器。 - `"program"`: 设置为要调试的可执行文件的路径。 - `"cwd"`: 设置为工作目录的路径。 - `"MIMode"`: 设置为`"gdb"`以使用GDB作为调试器。 - `"miDebuggerPath"`: 设置为GDB可执行文件的路径。 5. 在代码中设置断点,你可以使用鼠标左键单击行号来设置断点,或者在代码行上右键单击并选择“添加断点”。 6. 按下F5或选择菜单栏中的“调试”>“开始调试”来启动调试会话。 7. 在调试过程中,你可以使用调试面板中的各种功能,例如单步执行、查看变量的值和堆栈跟踪等。 通过以上步骤,你可以在VS Code中成功调试C代码。如果你需要更详细的指导,可以参考引用中提到的文章《Linux下使用VS Code CMake调试C程序》。希望对你有帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [解决在VScode调试C++代码断点无效、断点错位的问题](https://blog.csdn.net/hypc9709/article/details/125906413)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* [VSCode调试C/C++项目](https://blog.csdn.net/qq_45488242/article/details/128414756)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值