4

None of my terminals on Windows 10 recognize cl 'as an internal or external command'.
I have Visual Studio 2022 installed and I've tried it on every terminal, including terminals in the Visual Studio 2022 under the Start menu.

I've tried the other solutions to Stack Overflow. I tried setting an environment variable of cl to "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\Hostx86\x86\cl.exe"
Under 'Modify' in Visual Studio 2022 I have the boxes for 'Desktop development with C++' and 'Universal Windows Platform development' checked and installed.

I know there are other answers to this question but Visual Studio 2022 seems like it make have another solution.

Ant
  • 933
  • 2
  • 17
  • 33
  • 1
    ***None of my terminals on Windows 10 recognize cl 'as an internal or external command'.*** That means `cl` is not in any of the folders of your `PATH` environment variable. – drescherjm Jan 24 '22 at 22:19
  • 1
    Are you sure you installed the c++ tools? At least with earlier versions of VS they were not part of the default install. Run the installer again and make sure you have "Desktop development with C++" checked on the workloads tab, also look through the individual components tab and make sure everything you need is selected. – SoronelHaetir Jan 24 '22 at 22:22
  • @SoronelHaetir The boxes that I named in the OP are installed. Plus [here's a screenshot](https://imgur.com/rj2d190) of other optional C++ options in my Visual Studio program. I've done a restart recently too. – Ant Jan 24 '22 at 22:26
  • @drescherjm "cl is not in any of the folders of your PATH environment variable." Sorry, I don't know what this means exactly. – Ant Jan 24 '22 at 22:28
  • 1
    Related: [https://www.maketecheasier.com/what-is-the-windows-path/](https://www.maketecheasier.com/what-is-the-windows-path/) – drescherjm Jan 24 '22 at 22:38
  • @drescherjm Thank you. I think I found cl on Visual Studio 2022. It's at `C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\Hostx86\x86`. When I cd into that path I get `cl : Command line warning D9024 : unrecognized source file type 'C:\Program', object file assumed cl : Command line warning D9024 : unrecognized source file type 'Files\Microsoft', object file assumed cl : Command line warning D9024 : unrecognized source file type 'Visual', object file assumed cl : Command line warning D9024 :`... etc. – Ant Jan 24 '22 at 22:51
  • 1
    On the command line a space represents a separate argument. If you have a path with spaces it needs quoted. So to change directory to that folder you would type `cd "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\Hostx86\x86"` – drescherjm Jan 24 '22 at 22:52
  • I'm not sure where I put quotes around that path. I'm in the path and I type `cl` and this error is what I get. – Ant Jan 24 '22 at 22:53
  • 3
    There should be shortcuts on your Start menu to open a command prompt with the VC tools set for your desired build environment. E.g. "x64 Native Tools Command Prompt for VS 2019" or "x86_x64 Cross Tools Command Prompt for VS 2019". Run the shortcut that sets up the build environment you desire. – Raymond Chen Jan 24 '22 at 23:14
  • @RaymondChen Yes, I wrote in the second sentence in the OP that I tried all those terminals. – Ant Jan 24 '22 at 23:15
  • 1
    You wrote "I tried setting an environment variable of cl to C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat", which suggests that you did `set cl=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat` which doesn't work. You need to run the batch file, not set an environment to it. – Raymond Chen Jan 25 '22 at 00:16
  • @RaymondChen I'll update that. I wrote in an earlier comment that I managed to find the path `cl.exe` is in. It's at `C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\Hostx86\x86`. I set the environment variable here instead and it still doesn't work. I tried setting it for the user and the system. No dice. I can do this on Linux no problem. Just edit bashrc. I'm on Windows 10. In the commandline it still does not recognize cl. – Ant Jan 25 '22 at 00:20
  • I think you forgot to put quotation marks around the path. The spaces means that the compiler is at `C:\Program` with command line arguments `Files\Microsoft`, `Visual`, etc. But really, instead of setting the variables manually, let the pre-made batch files do them. – Raymond Chen Jan 25 '22 at 00:54
  • @RaymondChen I've tried it with and without. I'm actually trying to call `cl` from a make file and I know it needs `cl` to be an environment variable. After I delete environment variables I can execute cl only when in its path. I think I might have a unique problem with setting environment variables. I made a new OP about it [here](https://stackoverflow.com/questions/70842289/my-new-environment-variables-on-windows-10-are-not-working-though-i-can-set-new) – Ant Jan 25 '22 at 01:05
  • Based on the comments, you probably made too many changes before posting the question here, so that nobody can easily track the broken state and provide useful suggestions. You will have to go back to a clean Windows installation state and then try again from the scratch. That is really inconvenient but the only feasible way in most cases. – Lex Li Mar 21 '23 at 00:55

2 Answers2

7

Please find in your system this path:

C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\bin\Hostx64\x64

and add this path in the user variable path for your user name in the edit system environment variables.

Screendhot of the process is is given

this will work.

Kushagra Pal
  • 124
  • 5
  • Does the install using default settings for some reason not set the PATH variable? – edddd Mar 08 '23 at 18:26
  • 1
    It is recommended to use things like VS Developer Command Prompt temporarily load the paths to environment variables, not hard coded like this answer indicated. – Lex Li Mar 21 '23 at 00:51
0

Add the following path in both system and user environment variables path option

C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\bin\Hostx64\x64
Codemaker2015
  • 12,190
  • 6
  • 97
  • 81