未分类

VSCode编译、调试C++的json配置文件

准备工作

  1. vscode
  2. 下载C++插件

C++插件
就下这个就行,别的不需要,如果是远程到Linux,要加上remote插件

代码解析配置

ctrl+shift+p,选择C++:编辑配置

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [//头文件搜索目录,
                "${workspaceFolder}/**",//这个表示工作区路径下所有子目录
                "/usr/include/aarch64-linux-gnu/qt5/QtCore",
                "/usr/include/aarch64-linux-gnu/qt5"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc", //编译器路径
            "cStandard": "c11",
            "cppStandard": "c++17", //C++标准
            "intelliSenseMode": "linux-gcc-arm64"
        }
    ],
    "version": 4
}

编译配置

点配置任务

{
    "version": "2.0.0",
    "tasks": [//可以配置多个任务
        {
            "type": "cppbuild",//这个改不了
            "label": "exe qmake",//显示的名称
            "command": "qmake",//执行的命令
            "args": [
                "{workspaceFolder}/exe/exe.pro"//命令行参数
            ],
            "options": {
                "cwd": "{workspaceFolder}/exe"//命令行执行位置,对于qmake,会在执行qmake的地方生成makefile
            },
            "group": "build",//这个要改没几个能选的,建议不改
            "detail": "qmake"//显示的描述
        },
        {
            "type": "cppbuild",
            "label": "exe make debug",
            "command": "make",
            "args": [
                "debug",
                "-j2"
            ],
            "options": {
                "cwd": "{workspaceFolder}/exe"
            },
            "dependsOn": [
                "Hal qmake"
            ],
            "group": "build",
            "detail": "make debug "
        },
        {
            "type": "cppbuild",
            "label": "Hal clean",
            "command": "make",
            "args": [
                "distclean"
            ],
            "options": {
                "cwd": "{workspaceFolder}/exe"
            },
            "group": "build",
            "detail": "Hal make clean"
        },
    ]
}

调试配置

点这里,增加一个调试配置文件,点右下角的添加配置就可以自动生成一个配置项。

{

    "version": "0.2.0",
    "configurations": [//也可以添加多个,比如一个launch一个attach
        {
            "name": "(gdb) 附加",
            "type": "cppdbg",
            "request": "attach",
            "processId":"{command:pickProcess}",//加入这个用来选择需要附加的进程
            "program": "{workspaceFolder}/bin/Debug/exe",//要调试的程序
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        },
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "{workspaceFolder}/bin/Debug/exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "{workspaceFolder}/bin/Debug/",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

Remote的文件夹

ssh连接linux时,会在Linux上创建一些文件:

  • ~/.vscode-server 保存扩展插件的位置
  • ~/.cache/vscode-cpptools 保存文件跳转缓存,里面的ipch占用空间很大,可以删除,没有太大影响。

留言

您的电子邮箱地址不会被公开。 必填项已用*标注