Issue
I'm new to C++ and VS Code. When I follow some VS Code tutorials to create a .cpp
file, the .vscode
folder is created automatically and contains some .json
files. Also, CMakeLists.txt
is included at the top level of my project's src
directory.
I know CMakeLists.txt
is used to generate C++
executables. However, without setting CMakeLists.txt
, main.cpp
can also be executed based on .json
files. So I am confused about the difference between .json
and CMakeLists.txt
file usage.
Solution
If you don't use CMake (your CMakeLists.txt project config), then you'll have to use some other feature, such as just the cpptools extension without the CMake integration, where IntelliSense is configured using .vscode/c_cpp_properties.json file, or some other config if you are using a different IntelliSense extension such as the clangd one, build is typically done using a build task (.vscode/tasks.json), and debug is usually done with a launch configuration (.vscode/launch.json).
If you want more info on non-CMake setup things, see the related docs. For CMake + VS Code, see the docs for the CMake tools extension.
If you take the CMake route, the only cpptools extension-related setting you should need to set is configurationProvider
. Build would be handled by the CMake: Build
command (provided by the CMake Tools extension) instead of a build task, and debug should be handled by the CMake: Debug
command instead of a launch configuration (although I suppose you could still opt to go that route if you wanted, or use the cmake.debugConfig
setting). Problem detection will be build-diagnostic-based, so you'll need to rebuild to "refresh" problem detection for things like error squiggles in the editor.
Answered By - starball Answer Checked By - Senaida (WPSolving Volunteer)