问题描述
Visual Studio 2003和2005(也许我知道2008年)需要命令行用户在Visual Studio命令提示符中运行。当启动这个命令提示符时,它设置C ++编译器cl在编译时使用的各种环境变量。
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.
这并不总是可取的。例如,如果我想在Ant中运行cl,我想避免在Visual Studio命令提示符内运行Ant。运行vcvars32.bat不是一个选项,因为vcvars32.bat设置的环境将在运行时间(如果从Ant内运行)时丢失。
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).
有一个简单的方法来运行cl而不必从Visual Studio命令提示符下运行
Is there an easy way to run cl without having to run from within the Visual Studio command prompt?
推荐答案
编译器可以使用命令行(或makefile)就像任何其他编译器。你需要关心的主要事情是INCLUDE和LIB环境变量,以及PATH。如果你是从cmd.exe运行,你可以运行这个.bat来设置环境:
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:
如果您要使用makefile中的编译器,Cygwin,MinGW或类似的东西您需要手动设置环境变量。假设编译器安装在默认位置,这应该适用于Visual Studio 2008编译器和最新的Windows SDK:
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:
添加到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
添加到INCLUDE:
Add to INCLUDE:
- C:\Program文件\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\\\\\\\\\\\\\\\\\\包含
到LIB:
- C:\Program Files \Microsoft SDKs \Windows \v6.1\Lib
- C:\Program Files \Microsoft Visual Studio 9.0 \VC\lib
最低限度,但应该足够基本的东西。研究vcvarsall.bat脚本以查看您可能想要设置的内容。
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.
这篇关于使用Visual Studio的'cl'从正常的命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!