CMake在VS中使用远程调试
选中CMakeLists.txt, 右键-添加调试配置-选中"C\C++远程windows调试"
之后将 aunch.vs.json文件改为如下所示:
CMake在VS中使用远程调试时,Launch.vs.json中远程调试设置 ,远程电脑开启VS专用的RemoteDebugger
{"version": "0.2.1","defaults": {},"configurations": [{"type": "default","project": "CMakeLists.txt","projectTarget": "DmnCnc.exe (NcCoreQt\\Debug\\DmnCnc.exe)","name": "DmnCnc.exe (NcCoreQt\\Debug\\DmnCnc.exe)"},{"type_Explain": "远程模式, 指定项目是 dll 还是 exe(默认为 .exe)","type": "remoteWindows","authenticationType_Explain": "指定远程连接的类型,可能值为 windows 和 none。 默认值为 windows。 此值应与在远程计算机上运行的远程调试器上指定的身份验证设置相匹配,无身份验证时选none","authenticationType": "none","name_Explain": "指定“启动项”下拉列表中条目的名称,可以改成自己方便识别的名字","name": "DmnCnc-Remote","project_Explain": "指定项目文件的相对路径.通常调试CMake项目时不需要更改此值","project": "CMakeLists.txt","projectTarget_Explain": "指定生成 project 时调用的可选目标.目标必须与“启动项”下拉列表中的名称匹配(不能错,为本地的exe文件).","projectTarget": "DmnCnc.exe (NcCoreQt\\Debug\\DmnCnc.exe)","remoteMachineName_Explain": "指定启动程序的远程计算机的名称","remoteMachineName": "192.168.5.5:4026","cwd_Explain": "远程系统上将运行程序的目录的完整路径","cwd": "${debugInfo.defaultWorkingDirectory}","program_Explain": "远程计算机上的程序可执行文件的完整路径。使用CMake时,宏${debugInfo.fullTargetPath}可用作此字段的值.","program": "${debugInfo.fullTargetPath}","deploy_Explain": "指定要部署的额外文件或目录","deploy": [],"deployDirectory_Explain": "项目输出自动部署到的远程计算机上的位置.默认为C:\\Windows Default Deploy Directory\\<name of app>","deployDirectory": "D://Remote//Debug//","disableDeploy_Explain": "指定是否取消应部署文件,例如pdb调试文件","disableDeploy": false,"args_Explain": "传递给程序的命令行参数","args": [],"env": {}}]
}
在启动项中将出现DmnCnc-Remote的选择项,启动即可进行远程调试,注意需要将其他相关dll复制到远程exe同目录下.
具体可参数微软官网介绍:
教程:在远程 Windows 计算机上调试 CMake 项目 | Microsoft Learn
Launch.vs.json 架构参考 (C++) | Microsoft Learn
通过 CMake 安装和使用包 | Microsoft Learn