There are basically 3 ways to setup an environment for MSVC.
As @ben.boeckel correctly pointed out you can use a developer command prompt.
You can search in your taskbar for them once you have installed visual studio and the necessary components.
Make sure to take into account the variants though. In a typical VS installation they can be found here:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2019\Visual Studio Tools\VC
- x64 Native Tools Command Prompt for VS 2019.lnk
- x64_x86 Cross Tools Command Prompt for VS 2019.lnk
- x86 Native Tools Command Prompt for VS 2019.lnk
- x86_x64 Cross Tools Command Prompt for VS 2019.lnk
The one that begin with x86 are basically useless unless you are using a 32 bit OS. Technically you can use them on a 64 bit OS, however they are prone to failure on big enough applications. So I’d recommend only using the first 2.
- x64 Native Tools Command Prompt for VS 2019.lnk ← Use 64 bit tools to compile for 64 bit systems
- x64_x86 Cross Tools Command Prompt for VS 2019.lnk ← Use 64 bit tools to compile for 32 bit systems
What do these command prompts do? They setup the necessary environment variables for the MSVC compiler to do it’s job. For example the INCLUDE environment variable can be used to setup system level environment variables.
Microsoft has streamlined Method 1 with their integrated CMake support in Visual Studio. This way you can basically let Visual Studio handle it for you.
You can read more about it here:
Reverse engineer what the scripts in method 1 are doing and recreate the environment you need by hand.
I don’t recommend option 3.