I'm using VSCode (Version 1.74.2) on a Windows system. My project requires CMake (v 3.24) and a MSVC compiler.
I had MSVC 19.31 installed, which worked fine with VSCode and the CMake kits (automatically found).
Today I needed to upgrade MSVC to 19.34. Luckily this didn't cause any issues, except for the fact that VSCode doesn't find the compiler anymore.
Obviously I cleared any build-directories, so there were no remnants to the old compiler in CMake-files. And the compiler installation was verified with the developer command prompt.
I tried to scan for kits, "Visual Studio Professional 2022 Release - XXX" (XXX = [x86|x86_amd64|amd64_x86|amd64]) kits were found. I selected the "amd64" kit. Configuring resulted in:
[cmake] CMake Error at C:/Program Files/CMake-3.24.1/share/cmake-3.24/Modules/CMakeDetermineCCompiler.cmake:49 (message):
[cmake] Could not find compiler set in environment variable CC:
[cmake]
[cmake] cl.exe.
[cmake] Call Stack (most recent call first):
[cmake] CMakeLists.txt:9 (project)
[cmake]
[cmake]
[cmake] CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
[cmake] CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
[cmake] -- Configuring incomplete, errors occurred!
so obviously the compiler is not found.
I tried to delete the kits file and redo the scan. Adding the path in the C_Cpp > Default Compiler Path setting resulted in error.
Unable to resolve configuration with compilerPath "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.34.31933\bin\Hostx64\x64". Using "cl.exe" instead.
Ah, yes I also rebooted the machine, started VS, closed and reopened VSCode (several times) - this stuff sometimes helps with Microsoft products, but not this time.
I'd be glad of any helpful comments.
CodePudding user response:
This is an issue with configuration files for your project that you open with VS Code. The CMake
plugin for VS Code works in a way that it creates a minimum of two special files for your project:
c_cpp_properties.json
tasks.json
You are mainly interested in the c_cpp_properties.json
file, this is an example file which I took from a different question that I answered:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c 17",
"intelliSenseMode": "macos-clang-x64"
}
],
"version": 4
}
Yours will look similar.
You are interested in the element (usually at the bottom) called compilerPath
.
Since you updated MSVC
to a newer version you are still passing the wrong path here (I can tell you upgraded from 14.xxx).
By correcting the path to the newer version you will most likely fix your issue.
NOTE: You may need to update more of these variables (maybe even in both files). However this is where your issues stem from.