vscode intellisense can't find header files included in cmake project
Asked Answered
D

3

8

I have a cmake project that has:
A static library called Project1
A static library called Project2 that depends on Project1
An executable called Project3 that depends on both libraries

Everything is working as expected (makefiles, it is building and running normally, ...), but the problem is that vscode intellisense just does not find the header files in the folders specified using target_include_directories on each subdirectory.

The intellisense can find the default headers (iostream, vector, etc).

example: https://i.sstatic.net/XeVGW.jpg

I also tried putting the include directories in c_cpp_properties.json:

"includePath": [
    "${workspaceFolder}/Project1/src/**",
    "${workspaceFolder}/Project2/src/**",
    "${workspaceFolder}/Project3/src/**"
]

But it also didn't work.

I also tried putting the headers/sources manually in all CMakeLists.txt files (without using file(GLOB_RECURSE)) But it also didn't work.

This project is just a small example I made to show the problem, but it also happens in all the other projects.

The project can be found here: https://github.com/gabrielmaia2/CmakeTest

Diazine answered 8/2, 2021 at 4:21 Comment(4)
The cmake extension can do this stuff for you, as well as automate your builds for you.Garbe
I already have the cmake tools extension, but it still doesn't work.Diazine
I think there is an extension that is doing this. I disabled the extensions C/C++, Cmake Tools and Visual Studio Intellicode and it still showed that it couldn't find the header file.Diazine
did you configure the configuration provider? see also https://mcmap.net/q/798667/-how-can-i-set-up-c-c-intellisense-for-a-cmake-project-in-vs-code/11107541Winonawinonah
I
9

For those of you who are still experiencing this very irritating issue, the solution that worked for me was to just disable any C++ extensions, i.e. the Microsoft C++ extension pack, then enable them again.

Inorganic answered 1/1, 2023 at 16:6 Comment(1)
Had the same issue and what worked for me was disabling/re-enabling the CMake Tools extension.Evora
D
4

Found it. The extension "C/C++ Clang Command Adapter" was showing the errors because clang was not configured. I just disabled it (since I'm not using it) and now its working as expected.

Diazine answered 8/2, 2021 at 10:0 Comment(3)
thank you so much for posting your solution. I would have never found the "C/C++ Clang Command Adapter" extension without your answer.Myrwyn
How did you find it? I have very similar issue, but I do not have this extension installed.Itinerary
Thank you! I've been struggling for days with VSCode and intellisense errors, pragma guard errors, file not found while the project was compiling just fine. I have no idea when that dreaded extension was installed: "C/C++ Clang Command Adapter" but removing it solved all my problems.Yes
J
0

In the section "includePath" of your cpp_properties.json file, add "${workspaceFolder}/**" in order to include the path of all subdirectories of your workspaceFolder. This solved my problem with detecting header files with intellisense.

Jeopardous answered 17/3 at 15:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.