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
Select the item to open the prompt. You can test that you have the C++ compiler, cl.exe , installed correctly by typing 'cl' and you should see a copyright message with the version and basic usage description.
More precisely, the default path where you'll find the compiler is C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin .
The file cl.exe is located in a subfolder of "C:\Program Files (x86)" (for example C:\Program Files (x86)\Bench\Proxy\).
cl.exe is a tool that controls the Microsoft C++ (MSVC) C and C++ compilers and linker. cl.exe can be run only on operating systems that support Microsoft Visual Studio for Windows. You can start this tool only from a Visual Studio developer command prompt.
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'.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With