V
V
Vasily Vasilyev2017-11-01 01:12:59
C++ / C#
Vasily Vasilyev, 2017-11-01 01:12:59

How to add Visual Studio C++ compiler to powershell\cmd?

There is an installed Studio 2015.
Added to PATH C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\cl.exe
Created a test program (Hello World). Cursing on startup cl test.cpp:

test.cpp(1): fatal error C1034: iostream: не указан путь поиска включаемых файлов

Google suggested running the script C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\vsvars32. Launched. Nifiga, the error remains.
Question: how do you still run this damn compiler from the default command line?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Saboteur, 2017-11-01
@Basil_Dev

You need to add the directory (C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin) to PATH, not cl.exe
But the error says that you have not specified the search path for INCLUDED files.
That is, cl.exe itself finds it. You need to add the /I or -I option indicating where the include files are
located cl.exe -Ic:\src test.cpp

R
res2001, 2017-11-01
@res2001

The studio comes with a set of command scripts that configure the command line environment for the compiler to work. It is enough to run the command line through these scripts. Shortcuts to these scripts are located in the start menu in the studio folder.
For example, for VS2017 I have these:
x64 Native Tools Command Prompt for VS 2017
x86 Native Tools Command Prompt for VS 2017
Respectively for 64-bit and 32-bit assembly of applications. In 2015, there are similar studios, only the name is slightly changed.
Run command line through this script and everything will build.

R
Redee, 2021-01-20
@Redee

Compiling from cmd via cl.exe - setting the necessary environment.
To set system variables to the global environment - add to Path and create Include, LIB .
And change to your versions of MSVC, Windows SDK and bit depth x86 or x64.

To check the variables - you can simply run from the start menu - x64 Native Tools Command Prompt for VS 2019 and type "set path" or "set lib", or "set include".

Path
  • C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\bin\HostX64\x64

Include
  • C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\ATLMFC\include
  • C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\include
  • C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt
  • C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared
  • C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um
  • C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt
  • C:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt

LIB
  • C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\ATLMFC\lib\x64
  • C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.24.28314\lib\x64
  • C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\ucrt\x64
  • C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\um\x64

60084d043d7b6629048124.png
60084d0b6866d772151105.png
60084d10b1868232917890.png
You can also set the CL environment variable /MD to generate code with Dynamic Linking Runtime Libraries for a smaller executable size - the default is /MT release with static linking.
You can also override the option from cmd with a warning message about changing the option.
https://docs.microsoft.com/en-us/previous-versions...
https://docs.microsoft.com/en-us/previous-versions...
600878d7374bc198614365.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question