Using Visual Studio's 'cl' from a normal command line

The compilers can be used from command line (or makefiles) just like any other compilers. The main things you need to take care of are the INCLUDE and LIB environment variables, and PATH. If you're running from cmd.exe, you can just run this .bat to set the environment:

C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat

If you're trying to use the compilers from a makefile, Cygwin, MinGW, or something like that you need to set the environment variables manually. Assuming the compiler is installed in the default location, this should work for the Visual Studio 2008 compiler and the latest Windows SDK:

Add to PATH:

  • C:\Program Files\Microsoft SDKs\Windows\v6.1\Bin
  • C:\Program Files\Microsoft Visual Studio 9.0\VC\Bin
  • C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE

Add to INCLUDE:

  • C:\Program Files\Microsoft SDKs\Windows\v6.1\Include
  • C:\Program Files\Microsoft Visual Studio 9.0\VC\include
  • C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include

Add to LIB:

  • C:\Program Files\Microsoft SDKs\Windows\v6.1\Lib
  • C:\Program Files\Microsoft Visual Studio 9.0\VC\lib

These are the bare minimum, but should be enough for basic things. Study the vcvarsall.bat script to see what more you may want to set.


Create your own batch file (say clenv.bat), and call that instead of cl:

@echo off
:: Load compilation environment
call "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat"
:: Invoke compiler with any options passed to this batch file
"C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\cl.exe" %*

clenv.bat can now be invoked just like cl.exe, except that it will first load the needed environment variables first.


You can simply run the batch file which sets the variables yourself. In VS08 it's located at:-

C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat