码迷,mamicode.com
首页 > 编程语言 > 详细

基于VSCode的C/C++编程语言的构建调试环境搭建指南

时间:2020-04-02 19:45:20      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:pdb   build   failure   blog   script   linux   gdb   ssi   href   

环境

  • Win10+WSL-Ubuntu子系统
  • 编译器:GCC

vscode配置

插件配置

为在linux子系统下使用vscode,需要安装如下插件
技术图片

开发配置

以作业工程化编程实战callback接口为例,编译、调试项目时,需要分别配置tasks.json文件与lanuch.json文件

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": "gcc build active file",
            "command": "/usr/bin/gcc",
            "args": [
                "-g",
                "${fileDirname}/linktable.c",
                "${fileDirname}/menu.c",
                "-o",
                "${fileDirname}/link"
            ],
            "options": {
                "cwd": "/usr/bin"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

由于该项目有两个c文件linktable.c,menu.c需要编译,因此需要将tasks.json中的"args"一栏修改为"${fileDriname}/linktable.c"以及"${fileDirname}/menu.c"。参数列表中的"-g"是传递给gcc调用的,需要这个参数才能保证debug的正常进行。"-o"参数后是可执行程序的信息,在这里我将生成的程序命名为"link"。

lanuch.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": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "link",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

lanuch.json文件只需要修改"program"参数,将其修改为需要调试的程序名即可。

基于VSCode的C/C++编程语言的构建调试环境搭建指南

标签:pdb   build   failure   blog   script   linux   gdb   ssi   href   

原文地址:https://www.cnblogs.com/trydying/p/12622394.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!