mac 系统使用vscode 创建c/c++ 工程项目 并配置断点调试

mac 使用vsCode 创建c/c++ 工程项目 并配置断点调试

使用vscode 创建c/c++工程项目

准备工作

  • 使用 vscode 下载插件 C/C++ Project Generator

开始

一、使用快捷键

shift + command + p (mac) 
ctrl + shift + p (win)

二、输入并选择

Create c project # 创建c工程
Create c++ project # 创建c++ 工程


三、目录如下


配置断点调试

准备工作

  • 下载插件 CodeLLDB

  • 配置.vscode 里面的 launch.json 、tasks.json

launch.json 复制下面即可

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug",
            "program": "${workspaceFolder}/output/main",
            "args": [],
            "cwd": "${workspaceFolder}",
            "preLaunchTask": "Build with Clang"
        }
    ]
}

tasks.json 复制下面即可

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build with Clang",
            "type": "shell",
            "command": "clang++",
            "args": [
                "-std=c++17",
                "-stdlib=libc++",
                "${fileBasenameNoExtension}.cpp",
                "-o",
                "${fileBasenameNoExtension}",
                "--debug"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

注意事项

  • 每次修改源文件必须重新编译(不然断点不是修改后的内容)

断点调试查看资料

posted @ 2021-12-10 14:55  半截肥皂  阅读(2308)  评论(0编辑  收藏  举报