Microsoft KB Archive/75327

= Macros Do Not Become Part of the Environment =

Article ID: 75327

Article Last Modified on 12/1/2003

-

APPLIES TO


 * Microsoft Program Maintenance Utility 1.2
 * Microsoft Program Maintenance Utility 1.2
 * Microsoft Program Maintenance Utility 1.2
 * Microsoft Program Maintenance Utility 1.2
 * Microsoft Program Maintenance Utility 1.3
 * Microsoft Program Maintenance Utility 1.4
 * Microsoft Program Maintenance Utility 1.4
 * Microsoft Program Maintenance Utility 1.4
 * Microsoft Program Maintenance Utility 1.4
 * Microsoft Program Maintenance Utility 1.4
 * Microsoft Program Maintenance Utility 1.4
 * Microsoft Program Maintenance Utility 1.4

-



This article was previously published under Q75327



SUMMARY
When NMAKE defines a macro in a makefile, it does not define a corresponding environment variable for the processes NMAKE invokes. However, if an environment variable of the same name already exists, NMAKE reassigns it to have the same value as the macro.

For example, the first sample makefile below defines a CL macro. If an environment variable named CL exists, the CL macro in the makefile temporarily reassigns the CL environment variable such that the compiler only compiles files and does not link them. If the CL environment variable does not already exist, the CL macro is not added to the environment and does not change the compiler settings.



MORE INFORMATION
To create an environment variable in a makefile, use the SET command. The second sample makefile below demonstrates creating the CL environment variable if it does not already exist in the inherited environment.

The reassignment of existing environment variables can lead to unexpected errors. In the third sample program, if the environment variable 'LINK' is defined, one of the following errors will be generated:

LINK : error LNK1104: cannot open file &quot;link.obj&quot; (32 bit)

-or-

LINK : fatal error L1093: link.obj : object file not found (16 bit)

NTWIN32.MAK, the Win32 application master NMAKE definitions file for the Microsoft Win32 SDK for Windows NT programming samples, contains the macro definition &quot;link=link&quot;. Any makefile which has &quot;!include &quot; will fail with LNK1104, if the environment variable 'LINK' is defined.

The following warnings for the 32 bit compiler are generated for makefiles which define the MACRO 'cl' if the environment variable 'CL' was also defined:

Command line warning D4024 : unrecognized source file type 'cl',

object file assumed

Command line warning D4027 : source file 'cl' ignored

NOTE: If you use NMK.COM instead of NMAKE, you must use the SET command to reassign any environment variables. NMK.COM does not permit you to use macro assignments to override the environment. For more information, query in the Microsoft Knowledge Base on the following words:

NMK.COM and environment and macros

Sample Makefile #1
CL=/c ALL: cl test.c
 * 1) If the CL environment variable does not exist, this makefile # compiles and links TEST.C. If the CL environment variable exists, # the makefile changes its value to &quot;/c&quot; and prevents the linker from # running.

Sample Makefile #2
INCLUDE=d:\include ALL: set cl=/c cl test.c
 * 1) This is a modified makefile from sample 1. Because CL is set with # the SET command, the linker does not run.

Sample Makefile #3
link=link
 * 1) If the LINK environment variable does not exist, this makefile # compiles and links TEST.C. If the LINK environment variable exists, # the makefile changes its value to &quot;link&quot; and the linker error: # LNK1104 or L1093 will be generated.

ALL: cl /c test.c  $(link) test.o

Additional query words: kbinf 1.20 1.30 1.40 1.50

Keywords: KB75327

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.