ubuntu18下配置VS Code

配置逻辑主要是

launch.json指定预先处理的任务(preLaunchTask)及读取build文件(program)

tasks.json指定输入原始文件和输入build文件(args)

参考:https://www.cnblogs.com/JsonZhangAA/p/9750282.html

launch.json中的配置

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build",    //指定读取编译文件
            "preLaunchTask": "build",        //指定task
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

tasks.json中的配置:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "${workspaceFolder}/1.cpp",    //待编译源文件
                "-o",
                "build"    //输出编译文件名
            ],
            "problemMatcher": [
                "$gcc"
            ]
        }
    ]
}

编写好源文件(1.cpp)后,要build一次(ctrl+shift+b),若发现没有编译文件输出,则可能是用的命令不对,task.json->command改成"g++"试试

 另外还要注意检查源文件路径是否真如配置设定的那样

上一篇:性能压测:简单优化吞吐量测试、nginx动静分离优化


下一篇:vs code 配置c/c++环境