Linux下的VSCode进行C++编译及调试开发的配置

8 篇文章 0 订阅
4 篇文章 0 订阅

我这里配置的是Linux下的VSCode,使用的编译器是GCC,调试器是GDB
配置前先在终端中输入gcc,gdb(按q退出)看一下是否安装了g++和gdb
如果没有安装,deepin下直接输入
sudo apt-get install g++
sudo apt-get install gdb
sudo apt-get install gcc

先配置launch.json,这里面是关于C++或者C语言调试的配置
launch.json
这里有几个地方要注意,

  1. “preLaunchTask”: “gcc”,这句话表示在启动调试之前需要进行的任务,调试之前肯定是要编译撒,gcc这个值是后面task.json中label标签的值,你也可以取其他的。
  2. program这个标签中的值,注意要和后面的task.json中的cwd以及args标签中-o参数的值要对应。task.json中的cwd和"-o","${fileBasenameNoExtension}"决定了编译输出的文件名以及位置。program的值需要和这个位置一样,调试器才能找到该位置。
{
    // 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": "C++ (gdb)",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/build",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "/usr/bin/gdb",
            "preLaunchTask": "gcc",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": false
                }
            ]
        }
    ]
}

然后是关于C++编译的配置
task.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",
            "command": "/usr/bin/gcc",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileBasenameNoExtension}"
            ],
            "options": {
                // "cwd": "/usr/bin"
                "cwd": "${workspaceFolder}/build"
            },
            "problemMatcher": [
                "$gcc"
            ]
        }
    ]
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝域小兵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值