mac上使用vscode调试c++

1.首先安装一下c++插件

如图

重启vscode

2.写个hello world  压压惊 main.c

```

#include<stdio.h>

int main(void) {

    printf("hello world!\n");

}

```

3.command+shift+b 


点击创建生成任务


创建tasks.json文件


选择tasks.json模版

修改tasks.json

```

{

    // See https://go.microsoft.com/fwlink/?LinkId=733558

    // for the documentation about the tasks.json format

    "version": "2.0.0",

    "tasks": [

        {

            "label": "build",

            "type": "shell",

            "command": "gcc",

            "args": [

                "-g",

                "src/main.c",

                "-o",

                "main"

            ],

            "group": {

                "kind": "build",

                "isDefault": true

            }

        }

    ]

}

```

4.配置调试launch.json


修改launch.json

```


{

    "version": "0.2.0",

    "configurations": [

        {

            "name": "test Launch",

            "type": "cppdbg",

            "request": "launch",

            "program": "${workspaceFolder}/main",

            "args": [],

            "stopAtEntry": false,

            "cwd": "${workspaceFolder}",

            "environment": [],

            "externalConsole": true,

            "MIMode": "lldb"

        }

    ]

}

```

5.开始调试  (记得调试之前要command+shift+b)


©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容