Continuing on in the search for a responsive IDE for building large C++ codesets with CMake, the next stop is Visual Studio Code.
The initial install supplies a basic IDE editing environment.
Usability occurs when extensions are loaded. I have the following installed (versions are as of this writing):
- C/C++ for Visual Studio Code, v0.26, by Microsoft <== some sites say to disable this, but it is required by the debug function
- CMake, v0.0.17, by twxs, which provides CMake language support
- CMake Tools, v1.2.3, by Microsoft, which provides the build capability
- vscode-clangd, v0.0.19, is the clang language server, which provides code completion and symbol tables
Prior to installation of the extensions, on Debian, I installed the following packages first (in addition to the standard compilers):
- cmake
- clangd
- clangd-9
reddit - PROTIP: Use clangd instead of the official C/C++ extension suggests adding the following to .vscode/settings.json:
"C_Cpp.autocomplete": "Disabled", "C_Cpp.formatting": "Disabled", "C_Cpp.errorSquiggles": "Disabled", "C_Cpp.intelliSenseEngine": "Disabled",
In addition, I have a more recent version of clangd, so in .vscode/settings.json, I also have:
"clangd.path": "/usr/lib/llvm-9/bin/clangd",
My over all file looks like:
{ "clangd.path": "/usr/lib/llvm-9/bin/clangd", "C_Cpp.autocomplete": "Disabled", "C_Cpp.formatting": "Disabled", "C_Cpp.errorSquiggles": "Disabled", "C_Cpp.intelliSenseEngine": "Disabled", "C_Cpp.default.intelliSenseMode": "clang-x64", "editor.tabSize": 2 }
In the root directory of the project, a link is required (the setting "compileCommands" in .vscode/c_cpp_properties.json does not appear to be used by the clangd module) :
ln -s build/compile_commands.json .
2023/11/05 - Or add the following to .vscode/settings.json (which causes the file to be created and referenced directly in the basic workspace directory):
"cmake.copyCompileCommands": "${workspaceFolder}/compile_commands.json"
As a note, if compile_commands.json is not provided, then the following flag needs to be passed to CMake (seems to be defaulted "on" in current Visual Studio Code):
-DCMAKE_EXPORT_COMPILE_COMMANDS=1
Documentation for clangd is found at Getting started with clangd.