Visual Studio 2022 no longer recognizes symbols from directory specified by CMAKE_INSTALL_PREFIX

Daniel Jansson 1 Reputation point
2022-02-25T03:27:29.003+00:00

I was using Visual Studio 2019, building a C++ CMake project in WSL using VS's Linux development tools. I created by choosing "Open Folder" in VS because I think that was the only available option for CMake projects in VS2019, and maybe it still is?
In my CMakeSettings.json file I have specified a CMAKE_INSTALL_PREFIX, pointing to some directory unrelated to the rest of the project. In Visual Studio 2019, any files in this directory were includable and symbols from them would be recognized by VS. But since I switched to VS2022, any symbol or variable located in a file in the CMAKE_INSTALL_PREFIX directory is now unrecognized with a squiggly red line under it. Same goes for any #include statement attempting to include files from that directory. The solution still builds fine though! It's just the development that is made harder by the fact that I got all these squiggly lines everywhere, and can't F12 my way to any symbols or functions in those files.

Is this an introduced bug in VS2022 or am I doing something wrong? Is there some way to explicitly add a directory to a CMake project without physically copying it to the project directory?

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,722 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.