In the past, when writing C++ programs, I often used libraries like OpenCV. Configuring these environments was necessary when using Visual Studio. However, having adapted to VSCode, its robust extension features make it hard for me to switch to another IDE. After some exploration, I found that the CMake plugin with VSCode is a perfect match, effortlessly integrating tools like OpenCV and libTorch, and even supporting debugging capabilities. This has made writing C++ in VSCode much easier
Table of Contents
Install the plugins
To install the plugins in VSCode, you need two of them: the first one is CMake and the second one is CMake Tools
Quickly generate files
After pressing Ctrl+Shift+P to open the command line, hitting ‘Quick Start’ will generate two files in the current directory: ‘main.cpp’ and ‘CMakeLists.txt’
Choose the appropriate compiler
Choosing the right compiler, here we’ll use GCC as an example.
select executable
Setting up cmake
After selecting ‘configure’, set up the environment according to the contents of the arranged CMakeLists.txt; if there are any modifications to the file’s content, reconfiguration is necessary.
Using the debug feature
Using the debug feature is quite simple; just set a breakpoint where needed and then use the CMake debug function.