Borland出品的Delphi,有着闪电般的编译速度,但是在界面控件运用较多、工程项目较大的时分,编译一个工程仍需求一段时间,翻开庞大的Delphi IDE,也需求时间。其实,在一个工程开拓完毕,调试完成之后的Release编译,完整可以用命令行来实施,由于Delphi的编译器参数不像C++编译器那样繁杂。 笔者把Delphi联机手册中关于命令行编译(。mand-line 。piler)的几篇主题作了翻译,希冀对Delphi开拓人员有辅佐。 目录 1。 Command-line 。piler 命令行编译器 2。 Command-line 。piler options 命令行编译器选项 3。 Compiler directive options 编译器指令选项 4。 Compiler mode options 编译形式选项 5。 DCC32。CFG file 编译器配置文件DCC32。CFG 6。 Debug options 调试选项 7。 Directory options 目录选项 8。 IDE 。mand-line options IDE命令行选项 9。 Generated files 几个IDE自动生成的文件引见 Command-line 。piler 命令行编译器 Delphi's 。mand-line 。piler (dcc32。EXE) lets you invoke all the functions of the IDE 。piler (DELPHI32。EXE) from the DOS 。mand line (see IDE 。mand-line options。 Run the 。mand-line 。piler 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 。rmation to the 。piler and filename is the name of the source file to 。pile。 If you type dcc32 alone, it displays a help screen of 。mand-line options and syntax。 零或多个参数给编译器提供音讯,文件名指定需求编译的源文件名。假设你独自输入dcc32,它会显现一个关于命令行编译的选项和语法的屏幕。 If filename does not have an extension, the 。mand-line 。piler assumes 。dpr, then 。pas, if no 。dpr is found。 If the file you're 。piling to doesn't have an extension, you must append a period (。) to the end of the filename。 假设文件名没有扩展名,命令行编译器会查找扩展名为。dpr的同名文件,假设找不到,则查找扩展名为。pas的同名文件。假设你的源文件确实没有扩展名,你需求在文件名的开端增加(。)。 If the source text contained in filename is a program, the 。piler creates an executable file named filename。EXE。 If filename contains a library, the 。piler creates a file named filename。DLL。 If filename contains a package, the 。piler creates a file named filename。BPL。 If filename contains a unit, the 。piler creates a unit file named filename。dcu。 假设指定的源文件是一个工程文件,编译器会创立一个扩展名为。EXE的同名可实施文件。假设指定的源文件是一个库文件,编译器创立一个扩展名为。DLL的同名静态链接库文件。假设指定的源文件是一个包文件,编译器会创立一个扩展名为。BPL的同名包。假设指定的源文件是一个单元文件,编译器会创立一个扩展名为。dcu的目的代码文件。 You can specify a number of options for the 。mand-line 。piler。 An option consists of a slash (。) or immediately followed by an option letter。 In some cases, the option letter is followed by additional 。rmation, such as a number, a symbol, or a directory name。 Options can be given in any order and can 。e before or after the file name。 你可以为命令行编译器指定多个参数。一个参数包括一个破折号“-”(或“。”)和紧跟着的一个选项字符形成。一般状况下,选项字符前面会跟一些附加的音讯,如一个数字、一个符号、一个目录等。选项可以是恣意次第并且可以在源文件名前面或前面。 Command-line 。piler options 命令行编译选项 The IDE lets you set various options through the menus; the 。mand-line 。piler 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 。mand lines are equivalent and legal: IDE容许你运用菜单来设置各种编译选项,而命令行编译器容许你运用字符“。”作为分隔符来设定这些编译选项。你也可以运用连字符“-”来替代“。”,但是用“-”引出的参数之间必需用空格隔开。例如,下面两个命令都是同等的也是合法的: DCC -IC:\DELPHI -DDEBUG SORTNAME -$R- -$U+ DCC 。IC:\DELPHI。DDEBUG SORTNAME 。$R-。$U+ The first 。mand line uses hyphens with at least one blank separating options。 The second uses slashes and no separation is needed。 第一个编译命令用“-”引出参数,且参数之间有多个空格分隔。第二个编译命令用“。”引出参数,参数之间不用要分隔。 The following table lists the 。mand-line options。 In addition to the listed options, all single-letter 。piler directives can be specified on the 。mand 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目的文件 Kaddress Set image base address 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 。pilation $directive Compiler directives --Help 显现编译选项的辅佐。异样的,假设你在命令行独自输入dcc32,也会显现编译选项的辅佐。 --version 显现产品称号和版本 Compiler directive options 编译器指令选项 Delphi supports the 。piler directives described in Compiler directives。 The $ and D 。mand-line options allow you to change the default states of most 。piler directives。 Using $ and D on the 。mand line is equivalent to inserting the corresponding 。piler directive at the beginning of each source file 。piled。 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- 。piles MYSTUFF。pas with range-checking turned off, while: 不运用边境检查编译MYSTUFF。pas单元: dcc32 MYSTUFF -$R+ 。piles it with range checking turned on。 Note that if a {$R+} or {$R-} 。piler directive appears in the source text, it overrides the -$R 。mand-line option。 运用界面检查编译MYSTUFF。pas单元。假设将编译器指令{$R+}或{$R-}增加到源文件的开端,它将掩盖从命令行传入的参数。 You can repeat the -$ option in order to specify multiple 。piler directives: 你可以用多个“$”来指定多个编译器指令,如: dcc32 MYSTUFF -$R--$I--$V--$U+ Alternately, the 。mand-line 。piler lets you write a list of directives (except for $M), separated by 。mas: 命令行编译器容许作用逗号分隔的编译器指定列表,如: dcc32 MYSTUFF -$R-,I-,V-,U+ 只需求用一个“$”符号。 Only one dollar sign ($) is needed。 留意,由于$M的格式不一样,你不能在逗号分隔的指令列表中运用$M Note that, because of its format, you cannot use the $M directive in a list of directives separated by 。mas。 Conditional defines option 条件编译选项 The -D option lets you define conditional symbols, corresponding to the {$DEFINE symbol} 。piler directive。 The -D option must be followed by one or more conditional symbols separated by semicolons (;)。 For example, the following 。mand line: “-D”选项容许你定义一个编译条件,契合你用{$DEFINE symbol}定义的编译器指令。“-D”选项后必需跟随一或多个用分号分隔的编译条件符号,如下命令: dcc32 MYSTUFF -DIOCHECK;DEBUG;LIST defines three conditional symbols, iocheck, debug, and list, for the 。pilation 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: 假设你指定了多个“-D”选项,你可以衔接它们,如下: dcc32 MYSTUFF -DIOCHECK-DDEBUG-DLIST is equivalent to the first example。 同等于第一个例子。 Compiler mode options 编译形式选项 A few options affect how the 。piler 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 选项(-M) The 。mand-line 。piler has built-in MAKE logic to aid in project maintenance。 The -M option instructs 。mand-line 。piler to check all units upon which the file being 。piled depends。 Using this option results in a much quicker 。pile time。 命令行编译器运用结构逻辑的方式来维护工程。“-M”选项指示编译器检查一切与编译文件相关联的文件。用这个参数会招致编译时间增大。 A unit is re。piled under the following conditions: 一个源文件在下列状况下会重新编译: The source file for that unit has been modified since the unit file was created。 源文件被创立以来被修正过; 用“$I”指令包括的任何文件,用“$L”包括的任何。Obj文件,或用“$R”关联的任何资源文件。Res,比源文件中的要新; Any file included with the $I directive, any 。OBJ file linked in by the $L directive, or any 。res file referenced by the $R directive, is newer than the unit file。 The interface section of a unit referenced in a uses statement has changed。 单元接口局部interface的uses段有改动。 Units 。piled with the -Z option are excluded from the make logic。 在单元编译时指令“-Z”在结构逻辑期不被接受。 If you were applying this option to the previous example, the 。mand would be: 假设你在上一个例子中运用这个指令,编译命令就应当是: dcc32 MYSTUFF -M Build all (-B) option 编译一切 选项(-B) Instead of relying on the -M option to determine what needs to be updated, you can tell 。mand-line 。piler 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。 用于取代要知道哪些单元需求更新-M的选项,你可以运用-B选项来更新一切你的顺序中关联的单元。你不能在顺序中同时运用-M和-B。选项-B比-M速度更慢,而且它并不是必需的。 If you were using this option in the previous example, the 。mand would be 假设你在前一个例子中运用这个参数,编译命令就应当是: dcc32 MYSTUFF -B Find error (-F) option 查找过失 选项(-F) 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 。piled with debug 。rmation enabled (via the $D 。piler directive)。 当一个顺序由于运转时期过失而终止时,它会显现一个过失号和过失地址在过失发生时。用-Faddress选项来指定过失地址,你在源文件中能找到引发过失的位置,假设你的顺序和单元编译时附加了调试音讯(运用$D编译器指令)。 In order for the 。mand-line 。piler to find the runtime error with -F, you must 。pile the program with all the same 。mand-line parameters you used the first time you 。piled it。 为了命令行编译器能用-F选项查找运转时期过失,你必需传递与第一次编译时相同的指令列表。 As mentioned previously, you must 。pile your program and units with debug 。rmation enabled for the 。mand-line 。piler to be able to find runtime errors。 By default, all programs and units are 。piled with debug 。rmation enabled, but if you turn it off, using a {$D-} 。piler directive or a -$D- option, the 。mand-line 。piler will not be able to locate runtime errors。 先前提到过,你的顺序和单元必需启用调试音讯,命令行编译器才干查找运转时期过失。默许状况下,一切的顺序和单都是启用调试音讯的,除非你用{-D}或-$D-指令封锁它,这样,命令行编译器就不能查找运转时期过失了。 Use packages (-LU) option 运用包(-LU)选项 Use the -LU option to list additional runtime packages that you want to use in the application being 。piled。 Runtime packages already listed in the Project Options dialog box need not be repeated on the 。mand line。 运用-LU选项来在编译时增加你运用顺序中要用到的运转时期包。运转时期包曾经在“工程选项”对话框中罗列的,不用再在命令行中增加。 Disable implicit 。pilation (-Z) option (此选项在delphi6。0。7。0中有不同描画,在此不作翻译) The -Z option prevents packages and units from being implicitly re。piled later。 With packages, it is equivalent to placing {$ IMPLICITBUILD OFF} in the 。dpk file。 Use -Z when 。piling packages that provide low-level functionality, that change infrequently between builds, or whose source code will not be distributed。 Target file extension (-TX) option 目的文件扩展名(-TX)选项 The -TX option lets you override the default extension for the output file。 For example, 选项-TX容许你改写默许的输入文件扩展名。例如: dcc32 MYSTUFF -TXSYS generates 。piled output in a file called MYSTUFF。SYS。 生成的将是一个叫做MYSTUFF。SYS的文件。 Quiet (-Q) option 恬静形式(-Q)选项 The quiet mode option suppresses the printing of file names and line numbers during 。pilation。 When the 。mand-line 。piler 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 。pilation。 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 。mand line。 Each line in configuration file corresponds to an extra 。mand-line argument inserted before the actual 。mand-line arguments。 Thus, by creating a configuration file, you can change the default setting of any 。mand-line option。 你可以设置一个编译选项列表到一个叫做DCC32。CFG的配置文件中,它将用于编译时附加到命令行参数后。配置文件的每一行都相当于一个额外的命令行参数插入到实践的命令行参数前(留意,是实践参数前)。因此,你可以运用这个配置文件改动一些命令行参数的默许设置。 The 。mand-line 。piler lets you enter the same 。mand-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 。mand 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。 当dcc32发起时,它查找DCC32。CFG文件在以后目录。假设文件没有找到,dcc32会查找它所在的目录。 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 。piler directives: 以下是一个DCC32。CFG配置文件的例子,定义了关于文件包括、OBJ文件包括、单元文件搜寻途径音讯,并改动了编译器指令$O和$R的默许值。 -IC:\DELPHI\INC;C:\DELPHI\SRC -OC:\DELPHI\ASM -UC:\DELPHI\UNITS -$R+ -$O- Now, if you type: 往常,假设你输入: dcc32 MYSTUFF the 。piler 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 。piler has two sets of 。mand-line options that enable you to generate external debugging 。rmation: the map file options and the debug 。 options。 编译器有两个命令行参数可以生成外部调试音讯:MAP文件选项和调试音讯选项。 Map file (-G) options Map文件(-G)选项 The -G option instructs the 。mand-line 。piler 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 。rmation in the 。map file。 A 。MAP file is divided into three sections: 选项-G指示命令行编译器生成一个。map文件来检查一个可实施文件的布局。不同于可二进制的可实施文件和。dcu文件,。map文件是一个可读的文本文件,可以被打印或是其它文本编辑器编辑。选项-G后必需跟字符S、P或D,去决议你想要在。map文件列出的音讯。一个。MAP文件被分红三个节: 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) 。piled 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 。piled 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 。 (-V) options 布置选项(-V) The -V options (-V, -VN。 and -VR), which cause the 。piler to generate debug 。rmation, can be 。bined on the 。mand line。 选项-V、-VN、-VR会指示编译器生成调试音讯,它们能在命令行中组合运用。 Generate Turbo Debugger debug 。 (-V) option 生成Turbo Debugger运用的调试音讯的选项(-V) When you specify the -V option on the 。mand line, the 。piler appends Turbo Debugger 5。0-。patible external debug 。rmation at the end of the executable file。 Turbo Debugger includes both source- and machine-level debugging and powerful breakpoints。 当你在命令行中运用-V选项时,编译器会在可实施文件的开端附加与Turbo Debugger5。0一致的外部调试音讯。Turbo Debugger包括代码和硬件级别的弱小的断点。 Even though the debug 。rmation 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 。rmation appended to the executable file depends on the setting of the $D and $L 。piler directives in each of the modules (program and units) that make up the application。 For modules 。piled 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 whe 2011-10-24 7:49:57