Specifying Options with the CL Environment Variable

Use the CL environment variable to specify files and options without giving them on the command line. The environment variable has the following format:

SET CL=[[ [[option]] ... [[file]] ...]] [[/link [[link-libinfo]] ]]

The CL environment variable is useful if you often give a large number of files and options when you compile. Ordinarily, DOS limits the command line to 128 characters. The files and options that you define with the CL environment variable, however, do not count toward this limit. Therefore, you can define the files and options you use most often with the CL variable and then give only the files and options you need for specific purposes on the command line.

The information defined in the CL variable is treated as though it appeared before the information given on the CL command line.

Note that if you have given an option in the CL environment variable, you generally cannot turn off or change the option from the command line. You must reset the CL environment variable and omit the file or option that you do not want to use.

With DOS, you cannot use CL to set options that use an equal sign (for example, the /Didentifier= string option) With Microsoft C/C++, the define constants and macro option (/D) accept the number sign (#) as an equal sign (=). You can now use the CL environment variable to define preprocessor constants and macros (for example, /D identifier string).

You cannot use wildcards in filenames to specify multiple files with CL.

Examples

In the following example, the CL environment variable tells the CL command to use the /Zp, /Ox, and /I options during compilation and then to link with the object file \LIB\BINMODE.OBJ.

SET CL=/Zp2 /Ox /I\INCLUDE\MYINCLS \LIB\BINMODE.OBJ

CL INPUT.C

With CL defined as shown, the preceding CL command has the same effect as the command line:

CL /Zp2 /Ox /I\INCLUDE\MYINCLS \LIB\BINMODE.OBJ INPUT.C

That is, both specify structure packing on two-byte boundaries; perform maximum optimizations; search for include files in the \INCLUDE\MYINCLS directory; and suppress translation of carriage-return–linefeed character combinations for the source file INPUT.C.

In the following example, the CL environment variable instructs the CL command to compile and link the source files FILE1.C and FILE2.C.

SET CL=FILE1.C FILE2.C

CL FILE3.OBJ

The CL preceding command line has the same effect as the command line:

CL FILE1.C FILE2.C FILE3.OBJ

The following example illustrates how to turn off the effects of a CL option
defined in the environment:

SET CL=/Za

CL FILE1.C /Ze FILE2.C

In this example, the CL environment variable is set to the /Za option, which tells the compiler not to recognize Microsoft extensions to the C language. This option causes Microsoft-specific keywords to be treated as ordinary identifiers rather than as reserved words. The CL command specifies the inverse option, /Ze, which tells the compiler to treat language extensions as reserved words. The effect is the same as compiling with the command line:

CL /Za FILE1.C /Ze FILE2.C

Therefore, FILE1.C is compiled with language extensions turned off, and FILE2.C is compiled with language extensions enabled.