Closed kokostek closed 3 days ago
@gcampbell-msft I think the user this problem is because, #include
@v-frankwang, not quite. I have vs2022 installed, and cmake uses vs2022 generator and configure/build runs successfully. The problem is that the IntelliSense in vscode searches for headers in vs2017 include dir for some unknown reason, and shows false-positive error squiggles.
@gcampbell-msft @kokostek The user's problem is that cmake uses the vs2022 generator, but IntelliSense in vscode searches for header files in the vs2017 include directory. I reproduced the issue raised by the user and here are the steps to reproduce this issue
Repro steps:
1. Create a folder named test and open it with vscode.
2. Create a CMakeLists.txt file and add the following code:
cmake_minimum_required(VERSION 3.12)
project(VSCodeCMakeTest)
add_executable(main main.cpp)
target_compile_features(main PUBLIC cxx_std_20)
4. Create a main.cpp file and add the following code:
#include <cstdio>
#include <ranges>
int main(int argc, const char* argv[])
{
return 0;
}
6. Create a CMakePreset,json file and add the following code:
{
"version": 3,
"configurePresets": [
{
"name": "win-x64-debug",
"description": "Target Windows with the Visual Studio development environment.",
"generator": "Visual Studio 17 2022",
"binaryDir": "${sourceDir}/build/${presetName}",
"installDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_C_COMPILER": "cl.exe",
"CMAKE_CXX_COMPILER": "cl.exe",
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_CONFIGURATION_TYPES": "Debug"
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
"architecture": {
"value": "x64",
"strategy": "set"
}
}
]
}
Actual result:
@kokostek Looks like this is most likely a bug in cpptools: https://github.com/microsoft/vscode-cpptools/issues/12293 It should be fixed in cpptools version 1.21.0, which is available in pre-release. You can switch to the pre-release version on the cpptools extension page. Please let us know if that fixes your issue. Thanks!
@jophippe Thanks for the update! Yes, seems like it is fixed now with pre-release cpptools. Though I had to delete cache and reconfigure to make error squiggles go away.
Brief Issue Summary
I have two Visual Studios installed on my PC: 2017 and 2022. CMake project build targets VS2022 by specifying
"generator": "Visual Studio 17 2022"
inCMakePresets.json
.IntelliSense reports errors when I try to include some standard header, which is available in VS2022, but not available in VS2017, like![image](https://github.com/microsoft/vscode-cmake-tools/assets/14105978/f39a8942-7f7f-4551-ac97-f8109469a0c6)
<ranges>
for example:In the mean time, project configures and builds just fine.
When I try to navigate to included file which is not highlighted by IntelliSense (i.e.
<cstdio>
), I end up in the VS2017 include directory, which is also not ok:Project contents:
CMakeLists.txt
:CMakePresets.json
:main.cpp
:int main(int argc, const char* argv[]) { return 0; }
Debug Log
Additional Information
No response