VSCode连接远程服务器

VSCode下载安装包VSCode-win32-x64-1.70.1.zip

【配置文件】

launch.json

javascript 复制代码
{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/AlgoOnline",
            "args": [
                "-d",
                "-c", "/data/peizhiwenjianConfig.xml",
                // "-r", "/data/....
                // "-C","",

            ],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "gdb",
            "preLaunchTask": "compile",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

settings.json

javascript 复制代码
{
    "gotoSymbolStack.currentStackPosition": 0,
    "gotoSymbolStack.maxStackPosition": 0,
    "gotoSymbolStack.filePositionInfo": [],
    "files.associations": {
        "qbytearray": "cpp",
        "quuid": "cpp",
        "*.tcc": "cpp",
        "iosfwd": "cpp",
        "fstream": "cpp",
        "istream": "cpp",
        "cctype": "cpp",
        "clocale": "cpp",
        "cmath": "cpp",
        "cstdarg": "cpp",
        "cstddef": "cpp",
        "cstdio": "cpp",
        "cstdlib": "cpp",
        "cstring": "cpp",
        "ctime": "cpp",
        "cwchar": "cpp",
        "cwctype": "cpp",
        "array": "cpp",
        "atomic": "cpp",
        "strstream": "cpp",
        "bitset": "cpp",
        "chrono": "cpp",
        "complex": "cpp",
        "condition_variable": "cpp",
        "cstdint": "cpp",
        "deque": "cpp",
        "list": "cpp",
        "unordered_map": "cpp",
        "vector": "cpp",
        "exception": "cpp",
        "functional": "cpp",
        "initializer_list": "cpp",
        "iomanip": "cpp",
        "iostream": "cpp",
        "limits": "cpp",
        "mutex": "cpp",
        "new": "cpp",
        "ostream": "cpp",
        "numeric": "cpp",
        "ratio": "cpp",
        "sstream": "cpp",
        "stdexcept": "cpp",
        "streambuf": "cpp",
        "system_error": "cpp",
        "thread": "cpp",
        "cfenv": "cpp",
        "cinttypes": "cpp",
        "tuple": "cpp",
        "type_traits": "cpp",
        "utility": "cpp",
        "typeindex": "cpp",
        "typeinfo": "cpp",
        "memory": "cpp",
        "future": "cpp",
        "ranges": "cpp",
        "variant": "cpp",
        "bit": "cpp",
        "charconv": "cpp",
        "codecvt": "cpp",
        "compare": "cpp",
        "concepts": "cpp",
        "forward_list": "cpp",
        "map": "cpp",
        "set": "cpp",
        "unordered_set": "cpp",
        "algorithm": "cpp",
        "iterator": "cpp",
        "memory_resource": "cpp",
        "optional": "cpp",
        "random": "cpp",
        "regex": "cpp",
        "string": "cpp",
        "string_view": "cpp",
        "span": "cpp",
        "stop_token": "cpp",
        "valarray": "cpp",
        "cassert": "cpp",
        "qvariant": "cpp",
        "qvector": "cpp",
        "qdatetime": "cpp",
        "shared_mutex": "cpp",
        "*.ipp": "cpp",
        "csignal": "cpp"
    },
    "workbench.colorCustomizations": {
        "activityBar.activeBackground": "#61adfa",
        "activityBar.background": "#61adfa",
        "activityBar.foreground": "#15202b",
        "activityBar.inactiveForeground": "#15202b99",
        "activityBarBadge.background": "#bf0060",
        "activityBarBadge.foreground": "#e7e7e7",
        "commandCenter.border": "#e7e7e799",
        "sash.hoverBorder": "#61adfa",
        "statusBar.background": "#61adfa",
        "statusBar.foreground": "#e7e7e7",
        "statusBarItem.hoverBackground": "#61adfa",
        "statusBarItem.remoteBackground": "#61adfa",
        "statusBarItem.remoteForeground": "#e7e7e7",
        "titleBar.activeBackground": "#61adfa",
        "titleBar.activeForeground": "#e7e7e7",
        "titleBar.inactiveBackground": "#61adfa99",
        "titleBar.inactiveForeground": "#e7e7e799"
    },
    "peacock.remoteColor": "#61adfa"
}

tasks.json

javascript 复制代码
{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            // "command": "C:\\Program Files\\CMake\\bin\\cmake.exe",
            "command": "make",
            "args": [],
            "problemMatcher": [],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "compile",
            "type": "shell",
            "command": "make",
            "args": ["compile"],
            "problemMatcher": [],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

【将Linux服务器项目在VSCode内运行SOP】

1、首先使用ssh命令连接远程服务器

bash 复制代码
ssh [选项] 远程用户@远程主机地址

顺带提一嘴,和这个SOP无关

bash 复制代码
# 本地文件上传到服务器
scp /local/path/file.txt root@192.168.1.100:/remote/path/
 
# 服务器文件下载到本地
scp root@192.168.1.100:/remote/path/file.txt /local/path/

VSCode左下角选择Connect Current Windows to Host -> Add New SSH Host... -> 输入ssh命令

ssh hello@microsoft.com-A

输入完之后选择第一个选项C:\Users\user\.ssh\config,打开config选项,关闭config文件(config内有远程服务器Host HostName User)

重新点击左下角 -> Connect Current Windows to Host -> Linux-> 输入密码 -> 进入VSCode欢迎页

点击菜单栏文件 -> 打开文件夹 -> 选择项目所在的文件夹 -> 输入密码

【删除连接的服务器】

重新点击左下角 -> Open SSH Configuration File ... -> 选择第一个选项C:\Users\user\.ssh\config

删除文件内对应的Host HostName User参数

2、​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​在VSCode新开一个Terminal

在项目所在的文件夹内操作,使用ln命令,将项目生成的二进制文件软连接到该文件夹

bash 复制代码
ln -s ../build/ebi-debug/Applications/AlgoOnline ./

目的是为了与launch.json内的这一块对应

javascript 复制代码
configurations": [
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/AlgoOnline",
            "args": [
                "-d",
                "-c", "/data/gaoqian/workdir/beegfs/hunter/etc/AlgoConfig.xml",
                // "-r", "/data/donghong.li/workspace/beegfs/inspection/recipe-20241231-182723/",
                // "-C","",

            ],

在该文件夹./内就会出现一个软链接,ll命令查看显示为AlgoOnline -> ../build/ebi-debug/Applications/AlgoOnline

ll 文件路径/文件名称

可以查看文件的详细信息

......持续补充中


------2025.12.16

还好有大神助我,抓紧时间记录下来

我要一雪前耻

https://blog.csdn.net/yan_lai/article/details/146398935?spm=1001.2014.3001.5502

相关推荐
ulias21212 小时前
Linux系统中的权限问题
linux·运维·服务器
青花瓷13 小时前
Ubuntu下OpenClaw的安装(豆包火山API版)
运维·服务器·ubuntu
Dream of maid14 小时前
Linux(下)
linux·运维·服务器
齐鲁大虾14 小时前
统信系统UOS常用命令集
linux·运维·服务器
专吃海绵宝宝菠萝屋的派大星17 小时前
使用Dify对接自己开发的mcp
java·服务器·前端
大数据新鸟17 小时前
操作系统之虚拟内存
java·服务器·网络
克里斯蒂亚诺更新17 小时前
myeclipse的pojie
java·ide·myeclipse
楠奕18 小时前
CentOS7安装GoldenDB单机搭建及常见报错解决方案
linux·运维·服务器
GCTTTTTT19 小时前
远程服务器走本地代理
运维·服务器
剑锋所指,所向披靡!19 小时前
Linux常用指令(2)
linux·运维·服务器