VSCode调试C++时三个常用的json

  • c_cpp_properties.json - 编译环境相关的设置

打开方式:Ctrl+Shift+P进入命令行,搜索C/C++ Edit configuration

作用:指定头文件路径/编译器路径

{

    "configurations": [

        {

            "name": "Linux",              //环境名

            "includePath": [

                "${workspaceFolder}/**"   //指定头文件路径,这里${workspaceFolder}指定的是当前工作目录,如有需要在后面添加“,”后再添加新的路径。

            ],

            "defines": [],

            "compilerPath": "/usr/bin/g++",   //编译器的路径,可根据自己的安装情况进行设置

            "cStandard": "c11",

            "cppStandard": "c++17",       //设置使用的 C/C++ 标准

            "intelliSenseMode": "clang-x64"

        }

    ],

    "version": 4

}

  • task.json - 编译参数设置

打开方式:Ctrl + Shift + p进入命令行,选择 Tasks: Configure Default Build Task

作用:指定编译规则,和preLaunchTask配合使用可以实现自动编译。

{

  "version": "2.0.0",

  "tasks": [

    {

      "label": "build hello world",       //当前编译任务的名字,和preLaunchTask相对应

      "type": "shell",

      "command": "g++",                   //编译时执行的程序,调试ros时使用catkin_make DCMAKE_BUILD_TYPE=Debug

      "args": ["-g", "-o", "helloworld", "helloworld.cpp"],    //传递给 command 的参数,也就是编译参数

      "group": {

        "kind": "build",

        "isDefault": true                 //为 True 时,用户可以通过 Ctrl+Shift+B 直接运行编译任务

      }

    }

  ]

}

  •  launch.json - 调试相关的参数

打开方式:Ctrl+Shift+p 打开命令行,键入关键字 "launch",选择 "Debug:Open launch.json" -> "C++(GDB/LLDB)。

作用:调试程序,如设置debug,设置可执行文件的路径,预编译等

{

    "version": "0.2.0",

    "configurations": [

        {

            "name": "(gdb) Launch",

            "type": "cppdbg",

            "request": "launch",

            "program": "${workspaceFolder}/helloworld",        //可执行文件的完整路径

            "args": [],

            "stopAtEntry": false,           //是否在 main 函数处暂定执行

            "cwd": "${workspaceFolder}",

            "environment": [],

            "externalConsole": true,        //在打开外部终端执行程序,而不是在 VSCode 的控制台中运行

            "MIMode": "gdb",

            "preLaunchTask":“helloworld”,//和task中的label对应

            "setupCommands": [

                {

                    "description": "Enable pretty-printing for gdb",

                    "text": "-enable-pretty-printing",

                    "ignoreFailures": true

                }

            ]

        }

    ]

}

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值