Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
202 views
in Technique[技术] by (71.8m points)

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

Visual Studio 2003 and 2005 (and perhaps 2008 for all I know) require the command line user to run in the 'Visual Studio Command Prompt'. When starting this command prompt it sets various environment variables that the C++ compiler, cl, uses when compiling.

This is not always desirable. If, for example, I want to run 'cl' from within Ant, I'd like to avoid having to run Ant from within the 'Visual Studio Command Prompt'. Running vcvars32.bat isn't an option as the environment set by vcvars32.bat would be lost by the time cl was run (if running from within Ant).

Is there an easy way to run cl without having to run from within the Visual Studio command prompt?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 FilesMicrosoft Visual Studio 9.0VCvcvarsall.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 FilesMicrosoft SDKsWindowsv6.1Bin
  • C:Program FilesMicrosoft Visual Studio 9.0VCBin
  • C:Program FilesMicrosoft Visual Studio 9.0Common7IDE

Add to INCLUDE:

  • C:Program FilesMicrosoft SDKsWindowsv6.1Include
  • C:Program FilesMicrosoft Visual Studio 9.0VCinclude
  • C:Program FilesMicrosoft Visual Studio 9.0VCatlmfcinclude

Add to LIB:

  • C:Program FilesMicrosoft SDKsWindowsv6.1Lib
  • C:Program FilesMicrosoft Visual Studio 9.0VClib

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...