Windows下使用vscode连接Linux服务器进行C++代码运行与调试

参考链接:
vscode + SSH 配置 https://blog.csdn.net/irober/article/details/112724986
launch.json + tasks.json 配置 https://blog.csdn.net/jackuylove/article/details/120614761

launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "cppdbg",
            "request": "launch",
            "name": "GDB",
            "program": "可执行文件路径/可执行文件",
            "args": [
                "argv[1]",
                "argv[2]",
                "argv[3]"],//根据可执行文件输入参数,多个参数用逗号分隔
            "cwd": "${fileDirname}",
            "preLaunchTask": "Build",//与tasks.json的第三个任务名对应
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb", // debug 使用的程序
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
        }
    ]
}
tasks.json
{
    "version": "2.0.0",
    "options": {
        "cwd": "${fileDirname}/build"
    },
    "tasks": [
        {
            "type": "shell",
            "label": "cmake",
            "command": "cmake",
            "args": [
                ".."
            ],
        },
        {
            "label": "make",
            "group":
            {
                "kind": "build",
                "isDefault": true
            },
            "command":"make",
            "args": ["-j6"]
        },
        {
            "label": "Build",//与launch.json "preLaunchTask"对应
            "dependsOrder": "sequence",
            "dependsOn":[
                "cmake",
                "make"
            ]
        }
    ]

注意:
1.如果要调试代码,记得在CMakeLists.txt中设置 set(CMAKE_BUILD_TYPE "Debug")
2.要根据实际的工作目录路径对.json中进行设置和修改。

posted @ 2022-12-06 10:38  Du_huili  阅读(362)  评论(0编辑  收藏  举报