MAC VSCODE C++ debug环境配置

本文档详细介绍了如何在Visual Studio Code(VSCode)中配置C++的调试环境,包括安装必要的扩展如c/c++ extension和CodeLLDB,以及编辑c_cpp_properties.json、tasks.json和launch.json文件。通过配置,可以在Mac环境下使用LLDB进行调试,并针对一个简单的C++程序展示了如何设置断点并进行测试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先要了解,配置文件仅仅对当前的工作区有效(工作区是一个.code_workspace的文件)

 

因此一般不同的语言环境的相应文件夹会存放在不同的工作区中

本次配置的debug环境 需要用到的拓展:c/c++ extension, CodeLLDB

mac安装LLDB需要用到vsic文件直接载入

配置文件:

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
      {
        "label": "Build with Clang",
        "type": "shell",
        "command": "clang++",
        "args": [
          "${file}",
                "-std=c++11",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}.out",
                "-g",
                "--debug"
        ],
        "group": {
          "kind": "build",
          "isDefault": true
        }
      }
    ]
}

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": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug",
            "program": "${fileDirname}/${fileBasenameNoExtension}.out",
            "args": [],
            "cwd": "${workspaceFolder}"
        }
    ]
}

接着,就可以进行test了

以下面程序为例:

#include <iostream>
int main()
{
    for(int i=0;i<5;i++){
    std::cout<<"hey you"<<std::endl;
    }
   
    return 0;
 
}

在 for 行设置断点

如图所示 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值