1

I'm trying to get into SDL2 in C++ and I have followed all the steps in a variety of YouTube tutorials. I am using vs2019, and every time I try to run anything I get this error: Failed to locate: "CL.exe". The system cannot find the file specified. For example, it happens when I try running this code:

#include "SDL.h"
#undef main
#include <iostream>


int main() {
    int x = 1;
    std::cout << "Hello World!\n";
    std::cin.ignore();
    return 0;
}

I have followed all of the steps, but nothing seems to work. Similar questions have been asked, but their solutions don't work for me. I'm just running it in the editor. Can anybody help me?

  • 1
    How do you mean “_running this code_”? Do you mean you are trying to compile it at the command prompt with something like `cl /EHsc /Ox main.cpp`? Or are you using Microsoft’s Visual Studio IDE? – Dúthomhas Nov 05 '21 at 01:18
  • 3
    1) Verify you have a copy of "cl.exe" on your PC. Do a "find" on your hard drives. Start from your MSVS 2019 install dir. 2) Once you've confirmed you have it (e.g. under ` C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\`), ensure it's on your default path. Or open a "Visual Studio Developer Cmd Prompt" (a little .bat file that's installed with MSVS). 3) If you DON'T have it, then re-install MSVS. Ensure you specify the "C++" option. 4) Ensure you have the "Visual Studio Compiler" IDE, and *NOT* "Visual Studio Code". – paulsm4 Nov 05 '21 at 01:35

2 Answers2

4

You need to run VCVARSALL.BAT for Visual studio 2019 in the console for making cl.exe available.

Alternatively you can run "Developer Command Prompt for VS 2019" from the Start menu and run cl.exe there (after changing the appropriate working directory to one containing your code).

273K
  • 29,503
  • 10
  • 41
  • 64
1

I am going to post this as a potential answer, pending OP’s clarification to what he means by “running it in the editor”.

MSVS does not install with the C and C++ compiler and libraries unless you specifically ask for them. To install them you must re-run the installer. You will eventually get a screen with a lot of different options on it. It is a tabbed page with “Workloads”, “Individual Components”, and “Language Packs” at the top.

Find and make sure that you select both:

  • “Universal Windows Platform development”
  • “Desktop development with C++”

Continue as usual. The installer will update MSVS with the ability to compile C and C++ programs.

You can also read Microsoft’s instructions.

Dúthomhas
  • 8,200
  • 2
  • 17
  • 39
  • I tried that and I'm getting the same error. I already had desktop development with C++, but I added the universal windows platform development and it's coming up with the same error. I am literally just pressing f5 from source.cpp in the project in vs. Sorry if I'm being dumb, but I'm kind of new to this and I'm also 12. Thanks for answering, even if it didn't work. – DefenestratedChild Nov 05 '21 at 15:56
  • If that doesn’t work there is something significantly broken with your environment. Uninstall and reinstall. – Dúthomhas Nov 05 '21 at 16:01
  • I just found the executable on my PC but when I try to run the code it still comes up with the error. I know I have it in C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx86\x86, but I have no idea how to get it to work. – DefenestratedChild Nov 05 '21 at 16:04
  • I also tried adding cl.exe to my path in edit environment variables. – DefenestratedChild Nov 05 '21 at 16:07