美文网首页
vscode + linux 配置 c/c++

vscode + linux 配置 c/c++

作者: hourmor | 来源:发表于2019-04-21 01:01 被阅读0次

看过一些教程,linux下没有有关对整个工作区的任何c/c++文件的通用配置。这个是通用的,希望能为大家节省配置时间,当然,最终你们还是会像我这样,选择重新看官方文档。

 gdb + clang++   有坑,调试时无法显示stl容器内容,绝对不要这么搭配、、

最佳搭配是:

方案1:gdb + gcc/g++ 

或者

方案2:lldb + clang/clang++

上面2选1,自己安装gcc/g++ ,gdb 或lldb ,clang/clang++

插件自行安装

方案1就不需要codelldb这插件

直接放配置文件:

看自己选什么方案,可以删去不需要的搭配

launch.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": "clang++ lldb",

            "type": "lldb",

            "request": "launch",

            "program": "${fileDirname}/${fileBasenameNoExtension}.o",

            "args": [],

            "cwd": "${workspaceFolder}",

            "preLaunchTask": "clang++ build active file",

            "terminal": "integrated"

        },

        {

            "name": "clang lldb", // 配置名称,将会在启动配置的下拉菜单中显示

            "type": "lldb",

            "request": "launch",

            "program": "${fileDirname}/${fileBasenameNoExtension}.o",

            "args": [],

            "cwd": "${workspaceFolder}",

            "preLaunchTask": "clang++ build active file",

            "terminal": "integrated",

        },

        {

            "name": "gcc gdb", // 配置名称,将会在启动配置的下拉菜单中显示

            "type": "cppdbg", // 配置类型,这里只能为cppdbg

            "request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)

            "program": "${fileDirname}/${fileBasenameNoExtension}.o",

            "args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可

            "stopAtEntry": false, // 设为true时程序将暂停在程序入口处,我一般设置为true

            "cwd": "${workspaceFolder}", // 调试程序时的工作目录

            "environment": [], // 环境变量

            "externalConsole": false, // 调试时是否显示控制台窗口,一般设置为true显示控制台

            "internalConsoleOptions": "neverOpen", // 如果不设为neverOpen,调试时会跳到“调试控制台”选项卡,你应该不需要对gdb手动输命令吧?

            "MIMode": "gdb", // 指定连接的调试器,可以为gdb或lldb。但我没试过lldb

            "miDebuggerPath": "/usr/bin/gdb", // 调试器路径,Windows下后缀不能省略,Linux下则不要

            "setupCommands": [ // 用处未知,模板如此

                {

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

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

                    "ignoreFailures": false

                }

            ],

            "preLaunchTask": "gcc build active file" // 调试会话开始前执行的任务,一般为编译程序。与tasks.json的label相对应

        },

        {

            "name": "g++ gdb", // 配置名称,将会在启动配置的下拉菜单中显示

            "type": "cppdbg", // 配置类型,这里只能为cppdbg

            "request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)

            "program": "${fileDirname}/${fileBasenameNoExtension}.o",

            "args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可

            "stopAtEntry": false, // 设为true时程序将暂停在程序入口处,我一般设置为true

            "cwd": "${workspaceFolder}", // 调试程序时的工作目录

            "environment": [], // 环境变量

            "externalConsole": false, // 调试时是否显示控制台窗口,一般设置为true显示控制台

            "internalConsoleOptions": "neverOpen", // 如果不设为neverOpen,调试时会跳到“调试控制台”选项卡,你应该不需要对gdb手动输命令吧?

            "MIMode": "gdb", // 指定连接的调试器,可以为gdb或lldb。但我没试过lldb

            "miDebuggerPath": "/usr/bin/gdb", // 调试器路径,Windows下后缀不能省略,Linux下则不要

            "setupCommands": [ // 用处未知,模板如此

                {

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

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

                    "ignoreFailures": false

                }

            ],

            "preLaunchTask": "g++ build active file" // 调试会话开始前执行的任务,一般为编译程序。与tasks.json的label相对应

        }

    ]

}

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": "clang++ build active file",

            "command": "/usr/bin/clang++",

            "args": [

                "-g",

                "${file}",

                "-Wall",

                "-o",

                "${fileDirname}/${fileBasenameNoExtension}.o"

            ],

            "options": {

                "cwd": "/usr/bin"

            },

            "group": {

                "kind": "build",

                "isDefault": true

            },

            "presentation": {

                "echo": true,

                "reveal": "always",

                "focus": false,

                "panel": "shared"

            },

        },

        {

            "type": "shell",

            "label": "clang build active file",

            "command": "/usr/bin/clang",

            "args": [

                "${file}",

                "-g",

                "-Wall",

                "-o",

                "${fileDirname}/${fileBasenameNoExtension}.o",

            ],

            "options": {

                "cwd": "/usr/bin"

            },

        },

        {

            "type": "shell",

            "label": "g++ build active file",

            "command": "/usr/bin/g++",

            "args": [

                "${file}",

                "-g",

                "-Wall",

                "-o",

                "${fileDirname}/${fileBasenameNoExtension}.o"

            ],

            "options": {

                "cwd": "/usr/bin"

            },

            "group": {

                "kind": "build",

                "isDefault": true

            },

            "presentation": {

                "echo": true,

                "reveal": "always",

                "focus": false,

                "panel": "shared"

            },

            "problemMatcher": [

                "$gcc"

            ] // 如果你不使用clang,去掉前面的注释符

        },

        {

            "type": "shell",

            "label": "gcc build active file",

            "command": "/usr/bin/gcc",

            "args": [

                "${file}",

                "-g",

                "-Wall",

                "-o",

                "${fileDirname}/${fileBasenameNoExtension}.o",

            ],

            "options": {

                "cwd": "/usr/bin"

            },

            "problemMatcher": [

                "$gcc"

            ] // 如果你不使用clang,去掉前面的注释符

        }

    ]

}

相关文章

网友评论

      本文标题:vscode + linux 配置 c/c++

      本文链接:https://www.haomeiwen.com/subject/neargqtx.html