参考: https://www.jianshu.com/p/33e7a96e5809
文章目录
- 前言
- 环境准备
- Win10端
- SSH安装
- VSCode安装
- CentOs7端
- 安装C/C++
- Ubuntu18
- 开始配置VSCode
- 连接linux
- VSCode添加插件 c/c++
- 添加tasks.json配置和launch.json配置
前言
环境准备
vscode
centos7
gcc4.8
g++
ssh安装(安装git就行)
Win10端
SSH安装
VSCode安装
CentOs7端
安装C/C++
yum install gcc gcc-c++
查看gcc版本
gcc --version
Ubuntu18
gcc老是找不到Libc6等库 无法使用stdio等问题 暂未解决。
开始配置VSCode
ctrl+shift+P
输入ssh![在这里插入图片描述 [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++_vscode](https://file.cfanz.cn/uploads/png/2022/06/07/7/fN4Va6aKS8.png)
选择
Remote-SSH:Connect to Host
然后选择Configure SSH Hosts![在这里插入图片描述 [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++_c++_02](https://file.cfanz.cn/uploads/png/2022/06/07/7/762bTY59SB.png)
选择一个你的ssh配置文件 来存ssh信息![在这里插入图片描述 [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++_ssh_03](https://file.cfanz.cn/uploads/png/2022/06/07/7/aOe85XW89V.png)
config 添加信息
Host host_name(自定义)
HostName 目标linux IP
User 目标Linux用户名(例如root)
Port 22(端口 默认22)
例如
Host vm_centos7.0
HostName 192.168.1.30
User root
Port 22
Host vm_ubuntu18
HostName 192.168.1.28
User shiver
Port 22
PasswordAuthentication yes
连接linux
![在这里插入图片描述 [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++_json_04](https://file.cfanz.cn/uploads/png/2022/06/07/7/6eM51715GJ.png)
选择连接的LINUX![在这里插入图片描述 [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++_vscode_05](https://file.cfanz.cn/uploads/png/2022/06/07/7/cAZK3Q7K4S.png)
连接中![在这里插入图片描述 [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++_c++_06](https://file.cfanz.cn/uploads/png/2022/06/07/7/G3I4ROGc8N.png)
然后输入密码![在这里插入图片描述 [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++_linux_07](https://file.cfanz.cn/uploads/png/2022/06/07/7/0W45266CC6.png)
打开文件夹![在这里插入图片描述 [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++_c++_08](https://file.cfanz.cn/uploads/png/2022/06/07/7/17VcXe17J6.png)
![在这里插入图片描述 [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++_ssh_09](https://file.cfanz.cn/uploads/png/2022/06/07/7/2P676414WZ.png)
然后类似 这是我自己已有的文件夹![在这里插入图片描述 [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++_linux_10](https://file.cfanz.cn/uploads/png/2022/06/07/7/07D78Q3K8R.png)
VSCode添加插件 c/c++
选择插件选项![在这里插入图片描述 [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++_ssh_11](https://file.cfanz.cn/uploads/png/2022/06/07/7/5O343Nb24Z.png)
搜索C++(注意这是我已经安装到了linux情况,未安装情况如后图有个install in sshxxxx啥的)![在这里插入图片描述 [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++_ssh_12](https://file.cfanz.cn/uploads/png/2022/06/07/7/AJT01IWE3c.png)
![在这里插入图片描述 [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++_linux_13](https://file.cfanz.cn/uploads/png/2022/06/07/7/cYc6DBd4Hc.png)
添加tasks.json配置和launch.json配置
ctrl+shift+P 选择配置任务![在这里插入图片描述 [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++_ssh_14](https://file.cfanz.cn/uploads/png/2022/06/07/7/7Ue5Q785cF.png)
![在这里插入图片描述 [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++_ssh_15](https://file.cfanz.cn/uploads/png/2022/06/07/7/PEe79081B5.png)
复制以下内容进去:
我用的gcc 运行c++的话 你可以把gcc改为g++
{
"version": "2.0.0",
"tasks": [{
"label": "compile",
"command": "gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"problemMatcher": {
"owner": "cpp",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}然后在.vscode内容内添加launch.json文件![在这里插入图片描述 [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++_ssh_16](https://file.cfanz.cn/uploads/png/2022/06/07/7/537EX9W5YA.png)
复制以下内容进去:
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"preLaunchTask": "compile",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/home/shiver/Desktop/test",
"program": "/home/shiver/Desktop/test/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}然后创建main.c文件
int main(){
printf("helloworld!\n");
return 0;
}
右上角选择运行![在这里插入图片描述 [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++_vscode_17](https://file.cfanz.cn/uploads/png/2022/06/07/7/8D3FI5BX11.png)
![在这里插入图片描述 [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++_c++_18](https://file.cfanz.cn/uploads/png/2022/06/07/7/04HY551b45.png)
添加断点![在这里插入图片描述 [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++_ssh_19](https://file.cfanz.cn/uploads/png/2022/06/07/7/c88OID7S1d.png)
右上角选择调试![在这里插入图片描述 [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++_c++_20](https://file.cfanz.cn/uploads/png/2022/06/07/7/2540DG7c5K.png)










