'VSCode C/C++ Intellisense not working with CMake project
I'm trying to write a tool using libTooling. I got it set up so that it compiles with the example from the LLVM Documentation. However C/C++ Intellisense seems to not work with CMake projects.
My tool is located in:
<project>/clang-tools-extra/mytool
Now the C/C++ extension tries to read the compile_config.json and tells me <project>/build/compile_config.json could not be found, using includePath from c_cpp_properties.json instead.
I tried adding the include paths manually in my workspace settings:
{
"C_Cpp.default.includePath": [
"../../",
"../../clang/Frontend/",
"../../clang/Tooling/",
"../../llvm/Support/"
],
"C_Cpp.default.browse.path": [
"../.."
]
}
Or in a file c_cpp_properties.json. But it still searches for the includes in the wrong place. E.g. the include:
#include "llvm/Support/CommandLine.h"
It tries to find in <project>/llvm/include/llvm/Support/CommandLine.h. So apparently it reads something from command_config.json even though it says it can't find it (while it is there), but the wrong thing. It shouldn't add llvm/include at all.
Solution 1:[1]
You need to install cmake-tool extension (ms-vscode.cmake-tools) and add following configuration to your c_cpp_properties.json:
{
"configurations": [
{
"compileCommands": "${workspaceFolder}/_build/compile_commands.json",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
It is working for me
Solution 2:[2]
For VSCode 1.63+ (2022 or later):
1. Install the CMake Tools extension (ms-vscode.cmake-tools).
2. Put this in .vscode/c_cpp_properties.json:
{
"configurations": [
{
"name": "CMake",
"compileCommands": "${config:cmake.buildDirectory}/compile_commands.json",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
Solution 3:[3]
Maybe you just need to enable the extension cmake-tools, configure the CMakeLists.txt correctly, and then run cmake.
Normally, as long as there's no error with cmake, Intellisense should work properly.
Solution 4:[4]
If anybody else has this issue, I could solve it by switching from MSVC completion to clang.
With clang it actually gave me tooltips that showed how the paths were wrong.
See here how to set intellisense mode and location to clang: https://code.visualstudio.com/docs/languages/cpp
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Paweł Iwaneczko |
| Solution 2 | rustyx |
| Solution 3 | ???? |
| Solution 4 | CodeMonkey |
