本文介绍了从普通命令行使用 Visual Studio 的“cl"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 设置的环境会在 cl 运行时丢失(如果在 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).

有没有一种无需在 Visual Studio 命令提示符下运行就能运行 cl 的简单方法?

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

推荐答案

编译器可以像任何其他编译器一样从命令行(或生成文件)中使用.您需要注意的主要事项是 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:

添加到路径:

  • C:Program FilesMicrosoft SDKsWindowsv6.1Bin
  • C:Program FilesMicrosoft Visual Studio 9.0VCBin
  • C:Program FilesMicrosoft Visual Studio 9.0Common7IDE

添加到包括:

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

添加到 LIB:

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

这些是最基本的,但对于基本的东西应该足够了.研究 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"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 17:56