After setting up VS Code, installing the build tools and going through the tutorial here: https://code.visualstudio.com/docs/cpp/config-msvc
Visual Studio Code is unable to find the cl.exe to compile C++.
I replaced the path from the tutorial with the correct one on my hard drive (cl.exe is there).
// My Config
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17763.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.22.27905/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
// The tutorial build-task
{
"version": "2.0.0",
"tasks": [
{
"label": "msvc build",
"type": "shell",
"command": "cl.exe",
"args": [
"/EHsc",
"/Zi",
"/Fe:",
"helloworld.exe",
"helloworld.cpp"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal":"always"
},
"problemMatcher": "$msCompile"
}
]
}
When running the build task this error shows, although the compilerPath
is correct (the cl.exe is there) and helloworld.cpp exists as well. Running everything as administrator didn't help.
cl.exe : The term 'cl.exe' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path
is correct and try again.
At line:1 char:1
+ cl.exe /EHsc /Zi /Fe: helloworld.exe helloworld.cpp
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (cl.exe:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
The 'c_cpp_properties.json' file only configures IntelliSense in the C/C++ extension, so the compilerPath
option does not help with building.
Make sure you are launching VS Code from the Developer Command Prompt. This will set the necessary environment variables, including the location of 'cl.exe'.