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

简介: [笔记]Win10+VSCode+CentOs7+SSH+gcc 远程开发C++(二)

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
        }
      ]
    }
  ]
}

注意此处:

program填写编译生成的路径

cwd填写工作目录

配置gcc编译生成exe

然后创建main.c文件

#include <stdio.h>
int main(){
    printf("helloworld!\n");
    return 0;
}

右上角选择运行

添加断点

右上角选择调试

makefile构建

目录结构:

代码内容:

可参考 https://blog.csdn.net/z896435317/article/details/77948086

主要修改

launch.json

{
        "version": "0.2.0",
        "configurations": [
            {
                "name": "(gdb) Launch",
                "type": "cppdbg",
                "request": "launch",
                "program": "${workspaceFolder}/test",
                "args": [],
                "stopAtEntry": false,
                "cwd": "${fileDirname}",
                "environment": [],
                "externalConsole": false,
                "MIMode": "gdb",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    },
                    {
                        "description":  "Set Disassembly Flavor to Intel",
                        "text": "-gdb-set disassembly-flavor intel",
                        "ignoreFailures": true
                    }
                ],
                "preLaunchTask": "make_build"
            }
        ]
}

task.json:

{
        "version": "2.0.0",
        "tasks": [
            {
                "label": "make_clean", // 任务名称,与launch.json的preLaunchTask相对应
                "type":"shell",
                "command": "make", // 在shell中使用命令,如需加参数,可再添加args属性
                "args":[
                    "clean"
                ],
            },
            {
                "label": "make_build", // 任务名称,与launch.json的preLaunchTask相对应
                "type":"shell",
                "command": "make", // 在shell中使用命令,如需加参数,可再添加args属性
                "args":[
                ],
                "dependsOn":"make_clean"
            }
        ]
}

注意:也可以在配置文件launch.json右下角 添加配置-》选择gcc launch


相关实践学习
阿里云图数据库GDB入门与应用
图数据库(Graph Database,简称GDB)是一种支持Property Graph图模型、用于处理高度连接数据查询与存储的实时、可靠的在线数据库服务。它支持Apache TinkerPop Gremlin查询语言,可以帮您快速构建基于高度连接的数据集的应用程序。GDB非常适合社交网络、欺诈检测、推荐引擎、实时图谱、网络/IT运营这类高度互连数据集的场景。 GDB由阿里云自主研发,具备如下优势: 标准图查询语言:支持属性图,高度兼容Gremlin图查询语言。 高度优化的自研引擎:高度优化的自研图计算层和存储层,云盘多副本保障数据超高可靠,支持ACID事务。 服务高可用:支持高可用实例,节点故障迅速转移,保障业务连续性。 易运维:提供备份恢复、自动升级、监控告警、故障切换等丰富的运维功能,大幅降低运维成本。 产品主页:https://www.aliyun.com/product/gdb
相关文章
|
28天前
|
监控 Linux 应用服务中间件
centos7 部署zabbix5 踩坑笔记
centos7 部署zabbix5 踩坑笔记
|
24天前
|
人工智能 机器人 编译器
【C/C++】g++ 与 gcc的区别
【C/C++】g++ 与 gcc的区别
|
2月前
|
编译器 程序员 API
【踩坑记录】解决GCC 中C++ 17 的 std::filesystem 链接报错:undefined reference to `std::filesystem::path
【踩坑记录】解决GCC 中C++ 17 的 std::filesystem 链接报错:undefined reference to `std::filesystem::path
56 4
|
2月前
|
算法 编译器 C语言
【C/C++ 编译器的差异化】C++标准库在GCC和VS之间的表现差异
【C/C++ 编译器的差异化】C++标准库在GCC和VS之间的表现差异
152 1
|
2月前
|
编译器 程序员 C语言
【GCC 参数】 深入C++编译器常用标志:C/C++ 开发者必备的编译器参数
【GCC 参数】 深入C++编译器常用标志:C/C++ 开发者必备的编译器参数
42 0
|
2月前
|
算法 编译器 C语言
【C++ 函数 基本教程 第六篇 】深度解析C++函数符号:GCC与VS的名称修饰揭秘
【C++ 函数 基本教程 第六篇 】深度解析C++函数符号:GCC与VS的名称修饰揭秘
45 1
|
2月前
|
缓存 编译器 Linux
gcc 将C/C++ 热函数映射到大页的方法
gcc 将C/C++ 热函数映射到大页的方法
20 1
|
2月前
|
自然语言处理 编译器 调度
深入gcc编译器:C/C++代码如何变为可执行程序
深入gcc编译器:C/C++代码如何变为可执行程序
82 0
|
24天前
|
安全 Linux Shell
Linux SSH(Secure Shell)服务
Linux SSH提供安全网络协议,使用公钥加密技术确保远程服务传输安全。OpenSSH是实现SSH服务的免费开源工具,允许用户加密连接远程登录Linux服务器执行任务。SSH比Telnet更安全,防止数据被截获。SSH还支持端口转发和隧道,广泛应用于系统管理和网络维护,是安全远程访问服务器的重要工具。
21 1
|
2月前
|
安全 Shell Linux
【Shell 命令集合 文件管理】Linux ssh 远程主机之间复制文件 scp 命令使用教程
【Shell 命令集合 文件管理】Linux ssh 远程主机之间复制文件 scp 命令使用教程
40 0