'path of visual studio c compiler

i use to compile c/c++ code with gcc and now i want to pass on vsc. So i read for configure the path i should go in my visual studio file C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC and use vcvarsall.bat. When i do that with the powershell, it just doesn't work. If i do it with the cmd.exe, i will be able the use cl but if i open a new cmd.exe it won't work again. I try to put manually C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin in the path but it doesn't work either.
Thank you for all the future help.



Solution 1:[1]

Finally what i did it's create a shortcut and change the target to %comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat".

Solution 2:[2]

Newer versions of Visual Studio/Build Tools create shortcuts for you

Lately, if you install Visual Studio or VS Build Tools - with Develop C++ Desktop applications package, you should get a bunch of shortcuts automatically in the Windows Start menu that will launch a command prompt for 64 or 32 bit compiler.

Just open start menu search bar (shortcut - Windows key) and type command: enter image description here

You can do the following to find out how to run these files:

  1. Right-click on the item in Windows Start and choose Open File Location, which will open the shortcut link in File Explorer
  2. Right-click the shortcut link and choose Properties
  3. In the Properties windows, copy the "Target:" field (click in it and ctrl-a to select all, then ctrl-c to copy).
  4. The first item is the exe called (Should be %comspec%, and anything after the first space will be arguments.

For example, my x64 Native Tools Commmand Prompt for VS 2019 shortcut has a target of:

%comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvars64.bat"

Armed with this info, you can build a profile (see below) to launch terminals from other apps, or just take the last argument - the path and name of the batch file - and run it in a command terminal to set it up correctly to find all the VC tools.

Setting up a profile with a terminal in another tool/app

To setup a profile for apps like Microsoft's "Windows Terminal" app (multiple, tabbed terminals of different types - see Windows Store to download), or for Visual Studio Code:

Use the info from the shortcuts that link to the vcvars.bat batch files, as explained above to create a profile. For example, here is the JSON to add to Visual Studio Code to add an x86 (32-bit) and 64 bit command window to the dropdown list:

In .vscode/settings.json:

"terminal.integrated.profiles.windows": {
  "Visual C Dev Prompt (x64)": {
    "path": "cmd.exe",
    "args": [
      "/k",
      "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Auxiliary\\Build\\vcvars64.bat",
    ],
  },
  "Visual C Dev Prompt (x86)": {
    "path": "cmd.exe",
    "args": [
      "/k",
      "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\Common7\\Tools\\VsDevCmd.bat",
    ],
  },
},

Note that I changed the calling command from %comspec% to just cmd.exe, which should be in WINDOWS/system32 folder, which should already be on the path. I couldn't get it working with %comspec%. You can expand that in a command window to see the path on your PC as follows:

echo %comspec%

On my PC it was C:\WINDOWS\system32\cmd.exe.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 reduf
Solution 2 LightCC