在Windows上使用VSCode远程链接到Linux上开发并调试C++程序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Windows上使用VSCode远程链接到Linux上开发并调试C++程序相关的知识,希望对你有一定的参考价值。

参考技术A Debian 和 Ubuntu

CentOS

D:_Projects_Source_bak\2021\linux\ssh\config

编辑完config配置文件保存后,VSCode配置链接

右键点击远程目标(主机),选择任意一种connect
如果出现如下错误

main.c

Makefile

launch.json

tasks.json

按F5,选择工程类型:

选择gcc版本:

可以看到VSCode成功进入了调试模式,左边还能显示所有变量的值:

在 Windows 10 上激活 ssh-agent 的 VSCode

【中文标题】在 Windows 10 上激活 ssh-agent 的 VSCode【英文标题】:VSCode with activated ssh-agent on Windows 10 【发布时间】:2019-04-17 01:50:22 【问题描述】:

我想在 VSCode 中使用 git,使用我的 ssh-key。我目前的工作修复是这样的:

    启动 Powershell 运行 start-ssh-agent.cmd(git 安装) 运行代码

这将 ssh 代理或套接字链接到 VSCode,有效地允许我使用 git 命令的密钥。

我怎样才能把它变成一个合适的脚本?甚至更好:如何自动启动和配置 ssh-agent,使其全局可用(类似于 linux 上的 ssh-add)?

【问题讨论】:

看起来 VSCode 查看了SSH_AUTH_SOCK 环境变量。在运行ssh-agentssh-add 后通过MinGW (Git Bash) 运行code.exe,所以我尝试在PowerShell 中设置$env:SSH_AUTH_SOCK 并成功运行code。也许有办法启动ssh-agent,运行ssh-add,并在Windows 登录时注入SSH_AUTH_SOCK 【参考方案1】:

查看 VS Code 的帮助提示:https://code.visualstudio.com/docs/remote/troubleshooting#_setting-up-the-ssh-agent

总而言之,从管理 PowerShell 窗口运行以下命令:

# Make sure you're running as an Administrator
Set-Service ssh-agent -StartupType Automatic
Start-Service ssh-agent
Get-Service ssh-agent

这里应该设置Windows ssh代理服务自动启动,这样就不用每次都输入密码了。

【讨论】:

以上是关于在Windows上使用VSCode远程链接到Linux上开发并调试C++程序的主要内容,如果未能解决你的问题,请参考以下文章

12步搞定WSL 2,安装交互迁移VSCode远程调试应有尽有

使用vscode访问和修改远程计算机文件

使用 VSCODE 在 Windows 10 WSL 中远程开发

在 Windows 10 上激活 ssh-agent 的 VSCode

[vscode] --- vscode remote ssh远程登陆设置

实践与问题解决33vscode链接远程服务器,Import “XXX“ could not be resolved的问题解决