栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

[笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

[笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++

参考:
https://blog.csdn.net/weixin_45646006/article/details/105021237
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文件

#include 

int main(){
    printf("helloworld!n");
    return 0;
}

右上角选择运行

添加断点

右上角选择调试

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/958261.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号