参考: 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
选择
Remote-SSH:Connect to Host
然后选择Configure SSH Hosts
选择一个你的ssh配置文件 来存ssh信息
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
选择连接的LINUX
连接中
然后输入密码
打开文件夹
然后类似 这是我自己已有的文件夹
VSCode添加插件 c/c++
选择插件选项
搜索C++(注意这是我已经安装到了linux情况,未安装情况如后图有个install in sshxxxx啥的)
添加tasks.json配置和launch.json配置
ctrl+shift+P 选择配置任务
复制以下内容进去:
我用的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文件
复制以下内容进去:
{
"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;
}
右上角选择运行
添加断点
右上角选择调试