Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference in usage of c_cpp_properties/launch/tasks.json and CMakeLists.txt files when using VS Code?

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.

like image 558
KKKmelody Avatar asked Oct 16 '25 07:10

KKKmelody


1 Answers

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.

like image 101
starball Avatar answered Oct 18 '25 21:10

starball



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!