JMU JMU - Department of Computer Science
HelpTools
MS C/C++: The nmake Command


1 Purpose

The nmake command is used to automate the building of complex applications. Specifically, it uses the information in a makefile Click here for related information from another site. to "automatically" compile, link, etc... the parts of a complex application.

A makefile contains a list of targets (i.e., source files, object files, and executables), dependents (i.e., the files that a target depends on), and commands (i.e., what needs to be done if the target does not exist, if the target has an earlier time stamp than a dependent, or if the target is actually a "pseudotarget" without an associated file). Click here for related information from another site.

2 Syntax

The nmake command has the following syntax: Click here for information.

3 Arguments

option An option or switch (see below).
macro A macro. Click here for related information from another site.
target A target. If no targets are specified, the first target in the makefile is used.
command-file Command-line input.

4 Options

The list of valid options/switches for the nmake command includes the following:

5 Targets

A target is a valid file name or directory name. A target cannot contain more than 256 characters but it can contain path information.

Multiple targets can be specified in the same dependency line; separate them using spaces or tabs.

Note: If the target is a single letter, separate it from the colon (i.e., the : character) using a space (so it is not confused with a drive letter).

6 Dependents

A dependent is a valid file name. It can contain path information.

Multiple dependents can be specified in the same dependency line; seperate them using spaces or tabs.

Of course, a dependent can also be a target elsewhere in the makefile. The namke command will update dependents that are targets first. However, some care needs to be taken when creating makefiles.

Note: To split a "long" line, use the backslash (i.e., the \ character) after a dependent.

7 Examples

The following makefile has 3 description blocks:
    test.exe: test.obj module1.obj
      link test.obj module1.obj

    test.obj: test.cpp module1.h
      cl -c test.cpp

    module1.obj: module1.cpp module1.h
      cl -c module1.cpp

    

The first description block says that the target test.exe depends on two files, test.obj and module1.obj. If test.exe has an earlier time stamp than either of these files, test.exe should be rebuilt using the link command.

The second description block says that test.obj depends on test.cpp and module1.h, and that it can be created with the cl command.

The third description block says that module1.obj depends on module1.cpp and module1.h, and that it can be created with the cl command.

Assuming that this makefile is named makefile, the application test.exe can be built with the following command:

8 Predefined Rules

The nmake command makes use of a number of predefined inference rules Click here for related information from another site. that can greatly simplify makefiles. For example, .obj files will automatically be created from .c or .cpp files using the cl command (with the -c option).

While you are still learning to use the nmake command you should not make use of these predefined rules.

9 Error and Warning Messages

To get a description of an error or warning message, enter the error code below and click on the Find button.

Copyright 2018