2 years ago

#26949

test-img

Kewin

vscode mC++ Intellisense not finding paths with cmake subprojects

I am relatively new in using vscode. I have a project with a corresponding structure as below.

├─ subproject1
│  ├─ file1.h
│  ├─ subsubproject1
│     ├─ file2.h
|     ├─ file3.h

Where the CMake configuration would typically have subprojects added linearly

-- setting up subproject: 'subproject1'
-- setting up subproject: 'subproject1/subsubproject1'
(...)
-- Build files have been written to: /home/user/workspace/cmake-build-debug

I file2.cpp, I have:

#include subsubproject1/file3.h

Intellisense doesn't like and flag error:

cannot open source file "subsubproject1/file3.h".

This happens at multiple places in my code base and I am swarmed with error squiggles that shouldn't be there. It would not flag an error if I had instead:

#include file3.h

As these two files are in the same folders. But that's how my codebase is written, instead of relative path these are absolute paths from each subprojects. The compiler has no issue building that way. I just have a hard time making intellisense understand how the structure is laid out. I used the CMake extension that configured the project.

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "linux-gcc-x64",
            "compileCommands": "${workspaceFolder}/cmake-build-debug/compile_commands.json",
            "configurationProvider": "ms-vscode.cmake-tools",
            "mergeConfigurations": true,
            "browse": {
                "limitSymbolsToIncludedHeaders": true
            }
        }
    ],
    "version": 4
}

My understanding is that the relevant paths get added to intellisense through the compile_commands.json, and indeed when I run the C/C++ diagnostics I can see all the relevant directories listed but the problem seems to be linked on how intellisense uses relative paths instead of absolute paths from the subprojects.

Another strange thing to notice, before intellisense is fully loaded, I can access the directories fine when clicking on "go to definition/declaration" meaning it is able to see where they are, but after it is fully loaded and the errors described below appear, they become lost, it's like it has forgotten where they were.

Any help would be really appreciated I have spent a lot of time changing the C++ configuration.json, not using CMake, adding my paths manually but nothing seemed to work.

c++

cmake

intellisense

vscode-extensions

vscode-remote

0 Answers

Your Answer

Accepted video resources