在上两篇文章1,文章2中,我们介绍了c++开发的最佳实践,以及一些常见问题的解决方案。虽然笔者一直用vscode + remote-ssh + clangd阅读代码,但是调试代码时还是不免脱离vscode回到命令行,这多少让人有点分裂。因此本文将介绍如何在vscode中进行c++远程调试。
环境准备
插件
本文章依赖以下插件
-
remote-ssh,让vscode能够远程登陆远程开发机(我们的开发、编译、部署、调试都在这个环境中)
-
clangd: 一款优秀的c++插件,功能完备,支持重构,跳转,自动补全等功能
-
CodeLLDB: vscode调试器插件
其中remote-ssh和clangd的安装配置可参考我之前的文章
源代码
main.cpp
#include <iostream>
#include <vector>
#include <unistd.h>
int main(int argc, char *argv[])
{
int i = 0;
std::vector<int> v;
while (1)
{
v.push_back(i++);
::sleep(1);
}
return 0;
}
CMakeList.txt
# Set the minimum version of CMake that can be used
# To find the cmake version run
# $ cmake --version
cmake_minimum_required(VERSION 3.5)
# Set the project