首页 > 系统相关 >vscode连接linux|记录

vscode连接linux|记录

时间:2025-02-27 14:59:09浏览次数:11  
标签:bin gcc fileDirname vscode ++ json usr linux 连接

1.安装ssh插件

插件栏搜索ssh 进行安装

左侧栏图标

2.配置服务器

点击 连接到主机后 点击之前连接的或者新增

如果是新增一个 根据提示输入 ssh 用户名@主机ip -A

然后下一个选项默认回车

右下角选择 连接   上栏选择 继续   在输入密码即可链接

ctrl + j 打开linux系统终端操作框 

打开文件夹 选择写代码的目录 

  这里要根据提示输入密码

这里新建文件

运行的时候 如果报错 ctrl+鼠标点击可以跳到报错

3.创建 tasks.json

在上方的主菜单中,选择 Terminal>Configure Default Build Task ,将出现一个下拉菜单,显示 C++ 编译器的各种预定义编译任务 c++选择g++

上述操作将自动在.vscode文件夹下生成tasks.json文件。这里可以自行搜索

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "cppbuild",
			"label": "C/C++: gcc build active file",
			"command": "/usr/bin/gcc",
			"args": [
				"-fdiagnostics-color=always",
				"-g",
				"${file}",
				"-o",
				"${fileDirname}/${fileBasenameNoExtension}"
			],
			"options": {
				"cwd": "${fileDirname}"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": "build",
			"detail": "compiler: /usr/bin/gcc"
		},
		{
			"type": "cppbuild",
			"label": "C/C++: g++ build active file",
			"command": "/usr/bin/g++",
			"args": [
				"-fdiagnostics-color=always",
				"-g",
				"${file}",
				"-o",
				"${fileDirname}/${fileBasenameNoExtension}"
			],
			"options": {
				"cwd": "${fileDirname}"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"detail": "compiler: /usr/bin/g++"
		}
	]
}

4.调试Debug

创建launch.json

launch.json 文件用于在 Visual Studio Code 中配置调试器。接下来将创建launch.json 文件。

从主菜单中,选择 Run > Add Configuration…,选择C++ (GDB/LLDB)

之后可以在代码左边设置断点

然后Run -> Start Debugging,就可以开始debug了

标签:bin,gcc,fileDirname,vscode,++,json,usr,linux,连接
From: https://blog.csdn.net/lxl23shangan/article/details/145872614

相关文章