Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 688
CodeMonkey Avatar asked Feb 13 '19 13:02

CodeMonkey


2 Answers

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

like image 116
PhD Paweł Iwaneczko Avatar answered Oct 03 '22 10:10

PhD Paweł Iwaneczko


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
}
like image 28
rustyx Avatar answered Oct 03 '22 10:10

rustyx