Visual Studio Code MSVC cl.exe not found after installing build tools
Solution 1
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'.
Solution 2
In the documentation of Visual Studio Code you can see a solution to this issue. In the section of "C++ > Microsoft C++ on Windows > Troubleshooting" they explain that you need to open your projects from the Developer Command Promp
As an example:
cd projects/yourproject
code .
I haven't found other way of doing it.
Krck
Updated on June 25, 2022Comments
-
Krck about 2 years
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
-
Michele Iafrancesco over 4 yearsIs there a way to configure this from the JSON files? Or do I need to open VS Code each time from the VS Dev command prompt?
-
Callum Watkins over 4 years@Michele The docs state that "to use MSVC [...], you must run from a Developer Command Prompt", and this seems like the most reliable way of doing it. If you really want to try and avoid this though, it is possible to use the developer tools in an existing command window, and even to set
env
variables for debugging and tasks. Otherwise, it may be best to write this up as a separate question. -
Michele Iafrancesco over 4 yearsThanks, the first option worked! I was able to call the
vcvarsall.bat
from the command prompt and then run the compiler just fine! -
basjak over 3 yearsThis is the best way if you want to use the cl.exe compiler. remember, it's not a command prompt (cmd). it is the visual studio developer command promt.