VC++用命令行编译工程

此文来源于MSDN,关于命令行编译VC++工程,比较浅显易懂。

-------------------------------------------------------------------------------------------

 

Building a Project from the Command Line

 

You can build a Visual C++ project from the command line without first exporting a makefile (MAKEFILE, or filename.mak) and using the NMAKE utility.

 

The basic command syntax is

 

msdev FileName [/MAKE "ProjectName – ConfigName | ALL"] [/REBUILD /CLEAN /NORECURSE /OUT LogFile /USEENV]

 

where FileName is the name of your project (.dsp) or workspace (.dsw) file.

 

For example, the following syntax deletes all intermediate files and then builds a project called MyProject:

 

msdev MyProject.dsp /MAKE "MyProject – Win32 Debug" /REBUILD

 

The following syntax builds a workspace that contains (at least) two projects, building the release configuration of MyProject1 and all configurations of MyProject2, and directing the build output to a file called MyWorkspace.log:

 

msdev MyWorkspace.dsw /MAKE "MyProject1 – Win32 Release" "MyProject2 – ALL" /OUT MyWorkspace.log

 

Note   Projects created in Visual C++ versions earlier than 5.0 must first be converted before you can build them from the command line. To convert a project, open it inside the development environment.

 

You can also build all configurations of a certain type within a single project, for example, if you have defined multiple types of Debug configurations. For more information, see "Building by Type of Configuration."

 

Tip   Type msdev /? /OUT FileName to pipe the command syntax to a file.

 

The /MAKE Option


The /REBUILD, /CLEAN and /NORECURSE options all modify the /MAKE option, and are meaningless without it. Also, unless you specify a FileName after msdev, any /MAKE options will be ignored. /MAKE requires at least one configuration.

 

Parameters
Parameter          Description
FileName              

A valid workspace or project filename. Must have an extension of .dsp or .dsw.


ProjectName        

The project that contains the configurations you want to build. If Filename is a workspace file, ProjectName must be a part of that workspace.

 

ConfigName         

Any valid project configuration, or all configurations for a particular project. To build all configurations, simply type "ALL" for the configuration value (must be uppercase). Corresponds to the choices available from the Settings For drop-down list in the Project Settings dialog box. 


LogFile                

Name of an optional file used to store the build output information (valid only with the /OUT option). 

 


Options

Option              Operation
/MAKE "projectname1 – configuration1 | projectname1 – configuration2 | projectname2 – configuration1 | ALL"

Builds the specified configurations. The /CLEAN option modifies /MAKE so that the specified configurations are cleaned rather than built. 


/?

Displays usage information for the msdev command.


/CLEAN

Deletes intermediate files created during the build process for the specified configuration(s); does not build the project configuration(s). 


/REBUILD

Cleans and builds the specified configuration(s), including all dependent projects. Takes precedence if both /CLEAN and /REBUILD are specified.


/NORECURSE

Builds the specified project configuration(s) without building any dependent projects.


/OUT logfile

Creates a log file for the build output, which includes such information as syntax errors and warnings. If you don't specify a filename, the build output information is displayed at the command prompt and is not saved to a file. 


/USEENV

Directs the build system to use environment variables for the current build session, rather than the directory settings specified on the Directories tab (Tools menu, Options command). The PATH, INCLUDE and LIB paths must be set correctly for the build to succeed when /USEENV is specified.


/EX MacroName

Invokes the named macro (if the associated .dsm file is not loaded, this command will fail).


Tip   Type msdev /USEENV at the command line to launch Visual C++ and use the environment variables for the duration of that IDE session.

 

Building by Type of Configuration


For any single project, you can build all configurations of a certain type. The build system uses limited pattern matching to recognize the name of the configuration you specify.

 

For example, if your project contains Debug and Release configurations for both regular and UNICODE applications, you can build both configurations for only the UNICODE application by issuing the following command:

 

msdev MyProject.dsp /MAKE "MyProject – UNICODE"

 

Or, if your project contains several types of Debug and Release configurations, you can build all of the Debug configurations:

 

msdev MyProject.dsp /MAKE "MyProject – DEBUG"

 

This pattern matching gives you even more flexibility when customizing your batch builds.

 

-------------------------------------------------------------------------------------------

补充,如果是编译Release,则可以写成如下:

 

msdev MyProject.dsp /MAKE "MyProject – Release"

 

命令行编译比较适合的是批量编译,特别是在构建时使用是很方便的。可以将编译命令写成批处理文件,编译时直接调用BAT即可!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值