Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code MSVC cl.exe not found after installing build tools

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
like image 816
Krck Avatar asked Jul 26 '19 18:07

Krck


People also ask

How do I know if CL exe is installed?

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.

Where is MSVC compiler installed?

More precisely, the default path where you'll find the compiler is C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin .

Where is Cl exe located?

The file cl.exe is located in a subfolder of "C:\Program Files (x86)" (for example C:\Program Files (x86)\Bench\Proxy\).

What is CL exe in Visual Studio?

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.


2 Answers

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'.

like image 105
Callum Watkins Avatar answered Nov 14 '22 22:11

Callum Watkins


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.

like image 37
Mustafa Ali Saba Avatar answered Nov 15 '22 00:11

Mustafa Ali Saba