# Delphi 命令行编译指南

1. Command-line compiler

2. Command-line compiler options

3. Compiler directive options

4. Compiler mode options

5. DCC32.CFG file

6. Debug options

7. Directory options

8. IDE command-line options
IDE命令行选项
9. Generated files

Command-line compiler

Delphi's command-line compiler (dcc32.EXE) lets you invoke all the functions of the IDE compiler (DELPHI32.EXE) from the DOS command line (see IDE command-line options. Run the command-line compiler from the DOS prompt using the syntax:
Delphi’s命令行编译器(dcc32.exe)允许你从DOS命令行方式(参照：IDE命令行选项)实现IDE编译器(delphi32.exe)的所有功能。用DOS命令运行命令行编译器语法如下：
dcc32 [options] filename [options]
dcc32 [选项] [文件名] [选项]
where options are zero or more parameters that provide information to the compiler and filename is the name of the source file to compile. If you type dcc32 alone, it displays a help screen of command-line options and syntax.

If filename does not have an extension, the command-line compiler assumes .dpr, then .pas, if no .dpr is found. If the file you're compiling to doesn't have an extension, you must append a period (.) to the end of the filename.

If the source text contained in filename is a program, the compiler creates an executable file named filename.EXE. If filename contains a library, the compiler creates a file named filename.DLL. If filename contains a package, the compiler creates a file named filename.BPL. If filename contains a unit, the compiler creates a unit file named filename.dcu.

You can specify a number of options for the command-line compiler. An option consists of a slash (/) or immediately followed by an option letter. In some cases, the option letter is followed by additional information, such as a number, a symbol, or a directory name. Options can be given in any order and can come before or after the file name.

Command-line compiler options

The IDE lets you set various options through the menus; the command-line compiler gives you access to these options using the slash (/) delimiter. You can also precede options with a hyphen (-) instead of a slash (/), but those options that start with a hyphen must be separated by blanks. For example, the following two command lines are equivalent and legal:
IDE允许你使用菜单来设置各种编译选项，而命令行编译器允许你使用字符“/”作为分隔符来设定这些编译选项。你也可以使用连字符“-”来代替“/”，但是用“-”引出的参数之间必须用空格隔开。例如，下面两个命令都是等同的也是合法的：
DCC -IC:/DELPHI -DDEBUG SORTNAME -$R- -$U+
DCC /IC:/DELPHI/DDEBUG SORTNAME /$R-/$U+
The first command line uses hyphens with at least one blank separating options. The second uses slashes and no separation is needed.

The following table lists the command-line options. In addition to the listed options, all single-letter compiler directives can be specified on the command line, as described in Compiler directive options.

Option 　Description

Aunit=alias 设置单元别名
B 　 编译所有单元
CC 　编译控制台程序
CG 　编译图形界面程序
Ddefines 编译条件符号定义
Epath 　 可执行文件输出路径
Foffset 查找运行期间错误
GD 　生成完整.Map文件
GP 　生成.Map文件Public段
GS 　生成.Map文件Segment段
H 　 输出提示信息
Ipaths 　文件包含路径
J 　 生成.Obj目标文件
JP 　生成C++类型.Obj目标文件
LEpath 　包.BPL文件输出路径
LNpath 　.dcp文件输出路径
LUpackage　 使用运行期间包列表
M 　 编译有改动的源文件
Npath 　 dcu/dpu文件输出目录
Opaths 　.Obj文件(汇编目标代码文件)路径
P 　 按8.3格式文件名查找
Q 　 安静模式
Rpaths 　资源文件(.RES)路径
TXext 　 目标文件扩展名
Upaths 　单元文件路径
V 　 为Turbo Debugger生成调试信息文件
VN 　以.Giant格式生成包含命名空间的调试信息文件(将用于C++Builder)
VR 　生成调试信息文件.rsm
W 　 输出警告信息
Z 　 Disable implicit compilation
$directive Compiler directives --Help 显示编译选项的帮助。同样的，如果你在命令行单独输入dcc32，也会显示编译选项的帮助。 --version 显示产品名称和版本 Compiler directive options 编译器指令选项 Delphi supports the compiler directives described in Compiler directives. The$ and D command-line options allow you to change the default states of most compiler directives. Using $and D on the command line is equivalent to inserting the corresponding compiler directive at the beginning of each source file compiled. Delphi支持用编译器指令关键字描述的编译器指令。使用“$”和“D”命令行选项可以改变所有的默认编译器状态。用“$”和“D”命令行选项等同于在源文件的前面添加编译器指令。 Switch directive option 编译器指令选项开关 The$ option lets you change the default state of all of the switch directives. The syntax of a switch directive option is $followed by the directive letter, followed by a plus (+) or a minus (-). For example: “$”允许你改变每一种编译器指令默认状态。编译器指令的语法是“$”后紧跟一个指令字符，再跟一个“-”或“+”。例如： dcc32 MYSTUFF -$R-
compiles MYSTUFF.pas with range-checking turned off, while:

dcc32 MYSTUFF -$R+ compiles it with range checking turned on. Note that if a {$R+} or {$R-} compiler directive appears in the source text, it overrides the -$R command-line option.

You can repeat the -$option in order to specify multiple compiler directives: 你可以用多个“$”来指定多个编译器指令，如：
dcc32 MYSTUFF -$R--$I--$V--$U+
Alternately, the command-line compiler lets you write a list of directives (except for $M), separated by commas: 命令行编译器允许作用逗号分隔的编译器指定列表，如： dcc32 MYSTUFF -$R-,I-,V-,U+

Note that, because of its format, you cannot use the $M directive in a list of directives separated by commas. Conditional defines option 条件编译选项 The -D option lets you define conditional symbols, corresponding to the {$DEFINE symbol} compiler directive. The -D option must be followed by one or more conditional symbols separated by semicolons (;). For example, the following command line:
“-D”选项允许你定义一个编译条件，符合你用{$DEFINE symbol}定义的编译器指令。“-D”选项后必须跟随一或多个用分号分隔的编译条件符号，如下命令： dcc32 MYSTUFF -DIOCHECK;DEBUG;LIST defines three conditional symbols, iocheck, debug, and list, for the compilation of MYSTUFF.pas. This is equivalent to inserting: 定义了三个编译条件符号：IOCHECK,DEBUG,LIST,用于MYSTUFF.pas单元中。这等同于在源文件中插入以下语句： {$DEFINE IOCHECK}
{$DEFINE DEBUG} {$DEFINE LIST}
at the beginning of MYSTUFF.pas. If you specify multiple -D directives, you can concatenate the symbol lists. Therefore:

dcc32 MYSTUFF -DIOCHECK-DDEBUG-DLIST

is equivalent to the first example.

Compiler mode options

A few options affect how the compiler itself functions. As with the other options, you can use these with either the hyphen or the slash format. Remember to separate the options with at least one blank.

Make (-M) option

The command-line compiler has built-in MAKE logic to aid in project maintenance. The -M option instructs command-line compiler to check all units upon which the file being compiled depends. Using this option results in a much quicker compile time.

A unit is recompiled under the following conditions:

The source file for that unit has been modified since the unit file was created.

The interface section of a unit referenced in a uses statement has changed.

Units compiled with the -Z option are excluded from the make logic.

If you were applying this option to the previous example, the command would be:

dcc32 MYSTUFF -M
Build all (-B) option

Instead of relying on the -M option to determine what needs to be updated, you can tell command-line compiler to update all units upon which your program depends using the -B option. You can't use -M and -B at the same time. The -B option is slower than the -M option and is usually unnecessary.

If you were using this option in the previous example, the command would be

dcc32 MYSTUFF -B
Find error (-F) option

When a program terminates due to a runtime error, it displays an error code and the address at which the error occurred. By specifying that address in a -Faddress option, you can locate the statement in the source text that caused the error, provided your program and units were compiled with debug information enabled (via the $D compiler directive). 当一个程序由于运行期间错误而终止时，它会显示一个错误号和错误地址在错误发生时。用-Faddress选项来指定错误地址，你在源文件中能找到引发错误的位置，如果你的程序和单元编译时附加了调试信息(使用$D编译器指令)。
In order for the command-line compiler to find the runtime error with -F, you must compile the program with all the same command-line parameters you used the first time you compiled it.

As mentioned previously, you must compile your program and units with debug information enabled for the command-line compiler to be able to find runtime errors. By default, all programs and units are compiled with debug information enabled, but if you turn it off, using a {$D-} compiler directive or a -$D- option, the command-line compiler will not be able to locate runtime errors.

Target file extension (-TX) option

The -TX option lets you override the default extension for the output file. For example,

dcc32 MYSTUFF -TXSYS
generates compiled output in a file called MYSTUFF.SYS.

Quiet (-Q) option

The quiet mode option suppresses the printing of file names and line numbers during compilation. When the command-line compiler is invoked with the quiet mode option

dcc32 MYSTUFF -Q its output is limited to the startup copyright message and the usual statistics at the end of compilation. If any errors occur, they will be reported.

DCC32.CFG file
DCC32.CFG配置文件
You can set up a list of options in a configuration file called DCC32.CFG, which will then be used in addition to the options entered on the command line. Each line in configuration file corresponds to an extra command-line argument inserted before the actual command-line arguments. Thus, by creating a configuration file, you can change the default setting of any command-line option.

The command-line compiler lets you enter the same command-line option several times, ignoring all but the last occurrence. This way, even though you've changed some settings with a configuration file, you can still override them on the command line.

When dcc32 starts, it looks for DCC32.CFG in the current directory. If the file isn't found there, dcc32 looks in the directory where DCC32.EXE resides.

Here's an example DCC32.CFG file, defining some default directories for include, object, and unit files, and changing the default states of the $O and$R compiler directives:

-IC:/DELPHI/INC;C:/DELPHI/SRC
-OC:/DELPHI/ASM
-UC:/DELPHI/UNITS
-$R+ -$O-
Now, if you type:

dcc32 MYSTUFF
the compiler performs as if you had typed the following:

dcc32 -IC:/DELPHI/INC;C:/DELPHI/SRC -OC:/DELPHI/ASM -UC:/DELPHI/UNITS -$R+ -$O- MYSTUFF

Debug options

The compiler has two sets of command-line options that enable you to generate external debugging information: the map file options and the debug info options.

Map file (-G) options
Map文件(-G)选项
The -G option instructs the command-line compiler to generate a .map file that shows the layout of the executable file. Unlike the binary format of executable and .dcu files, a .map file is a legible text file that can be output on a printer or loaded into the editor. The -G option must be followed by the letter S, P, or D to indicate the desired level of information in the .map file. A .MAP file is divided into three sections:

Segment
Publics
Line Numbers
-GS outputs only the Segment section, -GP outputs the Segment and Publics section, and -GD outputs all three sections. -GD also generates a .DRC file that contains tables of all string constants declared using the resourcestring keyword.
-GS选项只输出Segment Section,-GS选项输出Segment和Publics,-GD输出所有的三个Sections.-GD选项也生成一个扩展名为.DRC的文件包含所有的用resourcestring关键字声明的字符串常量。
For modules (program and units) compiled in the {$D+,L+} state (the default), the Publics section shows all global variables, procedures, and functions, and the Line Numbers section shows line numbers for all procedures and functions in the module. In the {$D+,L-} state, only symbols defined in a unit's interface part are listed in the Publics section. For modules compiled in the {$D-} state, there are no entries in the Line Numbers section. 用默认的编译选项{$D+,L+}编译模块(程序或单元)，Publics Section列举所有的全局变量、过程和函数，Line Numbers Section列举模块中所有的过程和函数的行号。如果用{$D+,L-}编译选项编译模块，Publics Section中仅列举在单元的interface部分定义的符号。如果用{$D-}选项编译模块，在Line Numbers Section没有任何入口。
Debug info (-V) options

The -V options (-V, -VN. and -VR), which cause the compiler to generate debug information, can be combined on the command line.

Generate Turbo Debugger debug info (-V) option

When you specify the -V option on the command line, the compiler appends Turbo Debugger 5.0-compatible external debug information at the end of the executable file. Turbo Debugger includes both source- and machine-level debugging and powerful breakpoints.

Even though the debug information generated by -V makes the resulting executable file larger, it does not affect the actual code in the executable, and does not require additional memory to run the program.

The extent of debug information appended to the executable file depends on the setting of the $D and$L compiler directives in each of the modules (program and units) that make up the application. For modules compiled in the {$D+,L+} state, which is the default, all constant, variable, type, procedure, and function symbols are known to the debugger. In the {$D+,L-} state, only symbols defined in a unit's interface section are known to the debugger. In the {$D-} state, no line-number records are generated, so the debugger cannot display source lines when you debug the application. 附加到可执行文件上的调试信息的大小取决于编译这个应用程序要用到的第一个单元中的$D和$L编译器指令。使用编译器默认的选项{$D+，$L+}来编译模块，所有的常量、变量、类型、过程和函数的符号都会传递给调试器。使用选项{$D+，L-}编译，仅有在单元interface部分列出的符号才会传递给调试器。使用选项{$D-}编译，调试信息中没有生成行号信息，所以，调试程序时调试器不能显示源代码中的行。 The IDE internal debugger does not use Turbo Debugger debug information. Because generating Turbo Debugger debug information almost doubles compile/link time, you should turn off Turbo Debugger debug information generation except when you're debugging the application in Turbo Debugger. IDE内置的调试器不使用Turbo Debugger调试信息。因为生成Turbo Debugger调试信息几乎会成倍的增加编译或链接的时间，你可以关闭生成Turbo Debugger调试信息，除非你在Turbo Debugger中调试你的应用程序。 Generate namespace debug info (-VN) option 生成命名空间调试信息选项(-VN) When you specify the -VN option on the command line, the compiler generates namespace debugging information in the Giant format used by C++Builder. This allows the C++ compiler to find Pascal symbols. Use this switch when you are compiling code that will be used by C++Builder. 当你在命令行中使用-VN选项时，编译器会生成C++Builder中使用的Giant格式的命名空间调试信息。它让C++编译器能使用Pascal的符号。如果你的代码被用于C++Builder时你可以用这个选项。 Generate debug symbol info (-VR) option 生成调试符号信息选项(-VR) When you specify the -VR option on the command line, the compiler generates debugging symbol information in an .rsm file. 当你在命令行中使用-VR选项时，调试器会生成一个含有调试符号信息的.rsm文件。 Directory options 目录选项 Several options allow you to specify the directory lists used by the command-line compiler: include (-I), dcu input (unit search path, -U), resource (-R), object (-O), executable and dcu output (-E), and dcu output (-N). 一些选项允许你指定命令行编译器使用的目录列表：包含选项(-I)，dcu查找目录选项(-U)，资源文件目录选项(-R)，二进制对象目录选项(-O)，可执行文件和dcu文件输出目录选项(-E)，dcu文件 输出目录选项(-N)。 You can specify multiple directories, separated by semicolons, for some options. For example, this command line tells the command-line compiler to search for include files in C:/DELPHI/INCLUDE and D:/INC after searching the current directory: 一些选项中，你可以使用用”;”分隔的多个目录。例如，以下这个命令告诉命令行编译器，如果在当前目录中没有找到，再到” C:/DELPHI/INCLUDE”和”D:/INC”目录中搜索包含的文件： dcc32 MYSTUFF -IC:/DELPHI/INCLUDE;D:/INC If you specify multiple directives, the directory lists are concatenated. Therefore, 如果你使用了指定目录的多个指令，这些目录会被联接起来，因此： dcc32 MYSTUFF -IC:/DELPHI/INCLUDE -ID:/INC is equivalent to the first example. 它等同于第一个例子。 Executable directory (-E) option 可执行文件目录选项(-E) This option lets you tell the command-line compiler where to put the .EXE file it creates. It takes a directory path as its argument: 这个选项指示命令行编译器把生成的可执行文件输出到哪个目录。它取一个目录作为它的参数： dcc32 MYSTUFF -EC:/DELPHI/BIN dcc MYSTUFF -E/home/kylix/bin You can specify only one executable directory, which is also used for .DLL files. The -E option does not affect the location of .BPL (package) files. 你只能指定一个可执行文件路径，它同时也会被用于输出动态链接库(.DLL)的输出。-E选项对输出包文件(.BPL)没有影响。 If no such option is given, the command-line compiler creates .EXE files in the same directories as their corresponding source files. 如果没有这个选项，编译器会把生成的可执行文件放在相应的源文件的相同目录里。 Package directory (-LE) option 包文件输出目录选项(-LE) This option lets you tell the command-line compiler where to put the file it creates when it compiles a package. The syntax is the same as -E. 这个选项指示编译器把生成的包文件(.BPL)输出到哪个目录。它的语法同(-E)。 Package symbol info directory (-LN) option 包符号信息文件输出目录选项(-LN) This option lets you tell the command-line compiler where to put the .dcp (package symbol info) file it creates when it compiles a package. The syntax is the same as -E. 用这个选项你可以指示编译器在编译一个包时把生成的包符号信息文件.dcp输出到哪个目录。它的语法同(-E)。 Compiled unit directory (-N) option 单元目标文件.dcu输出目录选项(-N) This option lets you tell the command-line compiler where to put the .dcu (compiled unit) files it creates when it compiles a unit. The syntax is the same as -E. 用这个选项你可以指示编译器在编译一个单元文件时把生成的.dcu文件输出到哪个目录。它的语法同(-E)。 Include directories (-I) option 文件包含目录选项(-I) Delphi supports include files through the {$I filename} compiler directive. The -I option lets you specify a list of directories in which to search for include files.
Delphi支持使用编译器指令{$filename}来指定文件包含目录。-I选项允许你指定一个目录列表来搜索文件包含目录。 Unit directories (-U) option 单元文件搜索目录选项(-U) When you compile a program that uses units, the command-line compiler searches for source and compiled unit files in the current directory. The -U option lets you specify additional directories in which to search for units. 当你编译的程序使用了其它单元文件。编译器会在本目录搜索源文件和已编译单元。-U选项允许你指定其它的目录来搜索源文件和已编译单元。 Resource directories (-R) option 资源文件目录选项(-R) The compiler searches for resource files in the current directory. The -R option lets you indicate additional directories where dcc32 should look for resource files. 编译器会在当前目录搜索资源文件。-R选项允许你指示编译器在其它指定的目录搜索资源文件。 Object files directories (-O) option 对象文件目录选项(-O) Using {$L filename} compiler directives, you can link .OBJ files containing machine code created by external assemblers or other compilers, such as Borland C++. The -O option lets you specify a list of directories in which to search for such .OBJ files.

• earbao
• 2013年08月07日 22:07
• 1721

## delphi 命令行编译程序实例

• 2013年08月07日 22:03
• 23KB
• 下载

## Delphi 编译指令的使用方法

• xiongmao000738
• 2011年08月29日 19:39
• 4044

## 利用DCC自动编译Delphi工程组文件

Borland出品的Delphi，有着闪电般的编译速度，但是在界面控件使用较多、工程项目较大的时候，编译一个工程仍需要一段时间，打开庞大的Delphi IDE，也需要时间。其实，在一个工程开发结束，调...
• delphizhou
• 2013年11月19日 14:33
• 3767

## Delphi 编译指令与说明

{$IFDEF WIN32} 对于Delphi来说﹐左右大括号之间的内容是批注﹐然而 {$ (左括号后紧接着货币符号)对于Compiler(编译器)而言并不是批注﹐而是写给Comp...
• rznice
• 2012年10月11日 09:25
• 3494

## Delphi 命令行编译指南

Delphi 命令行编译指南
• shuaihj
• 2011年01月09日 22:14
• 2303

## Delphi命令行启动

• shuaihj
• 2004年10月30日 09:48
• 2027

## 电子书下载：Delphi 6 开发人员指南

• MaxWoods
• 2013年09月25日 14:04
• 1314

## delphi5开发人员指南-读书笔记

• lee576
• 2006年06月05日 20:48
• 1168

## delphi DCC32命令行方式编译delphi工程源码

Borland出品的Delphi，在TIOBE公布的2013年8月份编程语言排行榜中已经下降到14名。虽然排名下降，但是仍可以看出，使用delphi进行编程的还是大有人在，delphi现在确实有点落伍...
• sushengmiyan
• 2013年08月24日 20:59
• 5836

举报原因： 您举报文章：Delphi 命令行编译指南 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)