Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run cl.exe from cmd

I have installed Visual Studio Community 2017 with C++. I wanted to use its compiler from cmd. I am able to use it from Developer Command Prompt for VS 2017 but I am unable to use it from normal cmd. I have tried running vsvarsall.exe by right click-> run as administrator. But nothing happens. Seems like I have to set environment variables manually. Whenever I try to run the command

cl hello.c

it says hello.c(1): fatal error C1034: stdio.h: no include path set

like image 988
keen_learner Avatar asked Jun 13 '18 06:06

keen_learner


People also ask

What is CL CMD?

cl.exe is a tool that controls the Microsoft C++ (MSVC) C and C++ compilers and linker. cl.exe can be run only on operating systems that support Microsoft Visual Studio for Windows. You can start this tool only from a Visual Studio developer command prompt.

Why is Cl not working in command prompt?

If you see the error "The term 'cl.exe' is not recognized as the name of a cmdlet, function, script file, or operable program.", this usually means you are running VS Code outside of a Developer Command Prompt for Visual Studio and VS Code doesn't know the path to the cl.exe compiler.

Where is cl exe in Windows?

The file cl.exe is located in a subfolder of "C:\Program Files (x86)" (for example C:\Program Files (x86)\Bench\Proxy\). The file size on Windows 10/8/7/XP is 62,464 bytes.


1 Answers

Visual Studio includes a batch file that prepares the environment for you (actually, the Developer Command Prompt calls it under-the-hood).

I've never tried with the Community Edition, but for VS 2017 Professional it is located at "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars32.bat". It may vary if you changed the installation path, of course.

So, all you have to do is to invoke it:

call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars32.bat"

Something like following should appear

**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.7.3
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x86'

After that you can invoke cl, nmake, msbuild as within cmd.

You can also invoke vcvarsall.bat x86 instead (the vcvars32.bat is just a shortcut for that).


You can avoid typing it each time by creating a batch that automatically invokes it and then open a command prompt

call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars32.bat"
cmd

And then run that batch instead of cmd.

Another option is to add the "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\" to the path so you only have to type vcvars32.bat when you need the developer tools.

like image 166
cbuchart Avatar answered Oct 17 '22 04:10

cbuchart