【VS code】VS code远程编译调试环境配置

  1. 远程连接服务器
  2. 下载C++插件
    在这里插入图片描述
  3. 在服务器上安装gcc、gdb
yum install -y gcc
yum install -y gdb
  1. 点击运行或者按F5
    在这里插入图片描述
    然后在 .vscode中会出现三个文件

tasks.json (compiler build settings)
launch.json (debugger settings)
settings.json (compiler path and IntelliSense settings)

  1. 修改launch.json文件配置
    在这里插入图片描述
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C/C++: g++ Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++ 生成活动文件",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

program:代表可执行文件的路径,在此处使用的workspaceRoot代表当前的工作文件夹路径
args:代表运行可执行文件需要带的参数,注意该处为字符串数组
miDebuggerPath:代表当前调试使用的gdb程序路径,注意在linux上一般为默认路径
preLaunchTask:代表在进行调试任务之前需要触发的任务,也就是编译任务,任务的具体配置在tasks.json中;注意如果该项目为makefile项目的话,可直接在终端make,注意make -g,删除该配置不触发编译任务
6. 修改task.json文件配置
在这里插入图片描述

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ 生成活动文件",
            "command": "/usr/bin/g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "调试器生成的任务。"
        }
    ],
    "version": "2.0.0"
}

command:配置运行文件路径,也就是g++路径,一般linux路径为该默认路径
args:配置编译命令的参数,$ {file}为当前文件,可修改为"${workspaceFolder}/*.cpp",编译全部文件;" $ {fileDirname}/${fileBasenameNoExtension}"可以修改为具体的编译输出文件
7. 点击运行或者按F5
在这里插入图片描述

注:官方教程 https://code.visualstudio.com/docs/cpp/config-linux

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值