windows下 VScode+CMake+Linux远程调试

本文在这个基础上(跳过makefile):在Windows上使用VSCode远程链接到Linux上开发并调试C++程序_yizhiniu_xuyw的专栏-CSDN博客d​开发环境配置成功,记个流水账Linux安装相应工具apt install -y gcc make gdb请配置好Linux端的SSH功能给VSCode安装Remote Development扩展安装后可以看到一个新图标,点击后选中SSH Targets添加链接方式编辑这个文件,如果没有就新建:C:/Users/用户名/.ssh/config以下内容添加到末尾后编辑下:Host 设备名称(不影响连接) HostName Linux的地址(域名或iphttps://blog.csdn.net/yizhiniu_xuyw/article/details/119513666

.vscode下C/C++配置

1.快捷键(Ctrl+Shift+p),选择 C/C++:编辑配置(UI),进行设置

这一步会在.vscode下生成c_cpp_properties.json

.vscode下cmake编译配置

1.编写好程序的Makefile文件(这里就不细说了)

2.快捷键(Ctrl+Shift+p),输入task,选择 配置任务

3.随便选择一项,我这里选择的g++

4.以上会在.vscode文件夹下,生成一个tasks.json的配置文件,和默认配置

我修改好的 tasks.json 配置文件 (cmake)

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "CMakeBuild",
            "type": "shell",
            "command": "cmake ..",
            "args": [],
            "options": {
                "cwd": "${workspaceFolder}/build" 
            }
        },
        {
            "label": "build",
            "type": "shell",
            "dependsOn": ["CMakeBuild"],
            "command": "make clean; make",
            "options": {
                "cwd": "${workspaceFolder}/build" 
            }
        }
    ]
}

或者

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "cmake",
            "type": "shell",
            "command": "cmake",
            "args": ["../"],
            "options": {
                "cwd": "${workspaceFolder}/build"
            }
        },
        {
            "label": "make",
            "type": "shell",
            "command": "make",
            "args": ["-j20"],  //这里cmake -j20 表示 使用20核编译代码,可选项
            "dependsOn": ["cmake"],
            "options": {
                "cwd": "${workspaceFolder}/build"
            }
        },
        {
            "label": "build",
            "dependsOn": ["cmake","make"]
        }
    ]
}
 

.vscode下cmake调试配置

1.点击运行,选择添加配置

2.选择C/C++: (gdb) 启动,会生成 launch.json 配置文件,和配置模版,修改launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch", //配置名称,会在启动配置的下拉菜单中显示
            "type": "cppdbg", //配置类型,只能为cppdbg
            "request": "launch", //请求类型,可以为launch或attach
            "program": "${workspaceFolder}/build/可执行程序文件名", //将要调试的程序的路径【执行程序名不要遗漏了】
            "args": [], //调试时传递给程序的命令行参数
            "stopAtEntry": false, //设为true程序会暂停在入口处
            "cwd": "${workspaceFolder}/build", //调试程序时的工作目录
            "environment": [], //环境变量
            "externalConsole": false, //调试时是否显示控制台窗口
            "MIMode": "gdb", //指定连接的调试器,可以为gdb或lldb
            "miDebuggerPath": "/usr/bin/gdb", //gdb路径
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
            ,"preLaunchTask": "build" //调试开始前执行的任务,一般为编译过程,会调用tasks.json里面的任务,调试过程中没有代码改动的话可以注释掉
            //,"preLaunchTask": "build" //调试过程中没有代码改动的话可以注释掉,像这样
            
        }
    ]
}

参考:Windows使用VSCode远程Linux(ConteOS)开发/调试C/C++(超详细)_zy_workjob的专栏-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值