Having problem with compiling my code with "cl" command in windows

Hi, I am following the video game course with C++, and downloaded visual studio 2019 and VsCode. when i try to compile a code with the “cl” command (I have windows), it says that it doesnt recognize the command “cl”, Whereas I do succeed compiling with the g++ command (that you showed with linux and macOS). a photo of the exact error is attached. what may be the problem? thanks for helping!

Did you open VS Code through the developer command prompt?

1 Like

For me I ended up just building from the VS Command prompt instead of the integrated CMD or powershell terminal. I already had Visual Studio Community installed. Should be able to follow this guide to get it working but for me it seems the C/C++ extension in VS Code does not set up the PATH, INCLUDE, and LIB env variables correctly to the compiler tools.

I tried following the manual steps in this SO which fixed the missing “cl” binary issue with the PATH but it was still missing some INCLUDE references.

The advice is for an older VS version but the general folder structure is the same: Using Visual Studio's 'cl' from a normal command line - Stack Overflow

In the end, I ended up abandoning VS Code and just using VS on Windows as it is a better IDE IMHO.

It’s not supposed to. That’s what the developer command prompt does, using that to open VS Code would mean it keeps those environment variables.

I’d recommend against doing that as the developer command prompt does that for you.

Fair enough.

Do you mean to just run compile commands from the developer command prompt directly or open VS Code directly from within the developer command prompt? The former works but it would be nice to use the integrated terminal. The latter did not work for me so I am assuming that was not what you meant.

I meant the latter. Could you try closing all integrating terminals, all files and then File > Close Folder then trying again?

That worked! I also had installed some Windows updates overnight and a reboot may have helped as well. So others might want to try that as well.

I looked for “developer command prompt” and then opened VS Code with the “code” command:

image

Integrated terminal Windows cmd or powershell compilation then worked as expected.

1 Like

hi thanks for helping. I eventually succeeded and now it runs perfectly. thanks again!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms