命令行

来源:互联网 发布:数据库更新语句 update 编辑:程序博客网 时间:2024/05/17 07:53
  
Command-line compiler
Command-line compiler options
Compiler directive options
Compiler mode options
DCC32.CFG file
Debug options
Directory options
IDE command-line options
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:
dcc32 [options] filename [options]
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:
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.
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.
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+
Only one dollar sign ($) is needed.
  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:
dcc32 MYSTUFF -DIOCHECK;DEBUG;LIST
defines three conditional symbols, iocheck, debug, and list, for the compilation of MYSTUFF.pas. This is equivalent to inserting:
{$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.
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.
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).
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.     Use packages (-LU) option
Use the -LU option to list additional runtime packages that you want to use in the application being compiled. Runtime packages already listed in the Project Options dialog box need not be repeated on the command line.
Disable implicit compilation (-Z) option
The -Z option prevents packages and units from being implicitly recompiled later. With packages, it is equivalent to placing {$ IMPLICITBUILD OFF} in the .dpk file. Use -Z when compiling packages that provide low-level functionality, that change infrequently between builds, or whose source code will not be distributed.
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
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
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.
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.
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.
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.
Generate namespace debug info (-VN) option
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.
Generate debug symbol info (-VR) option
When you specify the -VR option on the command line, the compiler generates debugging symbol information in an .rsm file.
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).
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:
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
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.
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
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.
Package symbol info directory (-LN) option
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.
Compiled unit directory (-N) option
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.
Include directories (-I) option
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.
Unit directories (-U) option
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.
Resource directories (-R) option
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.
Object files directories (-O) option
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.
IDE command-line options
This topic lists and describes all of the options that you can use to start the IDE from the command line.
You must precede all options (unless otherwise noted) with either a dash (-) or a slash (/). The options are not case sensitive.Therefore, the following options are all identical: -d /d -D /D.
You use these options with the IDE startup command: delphi32.exe.
For example:
delphi32.exe -ns –hm
Starts the IDE with no splash screen and tracks memory allocation.
delphi32.exe -s dc:/test/source -d c:/test/myprog.exe –td
Starts the IDE and loads c:/test/myprog.exe into the debugger and used c:/test/source as the location for the source code while debugging. The -td and any other argument that appears after the -dexename debugger option is used as an argument to c:/test/myprog.exe.
General options
Option     Description
  Displays help for IDE command-line options.
hm   Heap Monitor. Displays information in the IDE title bar regarding the amount of memory allocated using the memory manager. Displays the number of blocks and bytes allocated. Information gets updated when the IDE is idle.
hv    Heap Verify. Performs validation of memory allocated using the memory manager. Displays error information in the IDE title bar if errors are found in the heap.
ns    No splash screen. Suppresses display of the splash screen during IDE startup.
np    No Project. Supresses loading of any desktop files on IDE startup and suppresses creation of a default project.
Option     Description
dexename      Loads the specified executable (exename) into the debugger. Any parameters specified after the exename are used as parameters to the program being debugged and are ignored by the IDE. A space is allowed between the d and the exename.
attach:%1;%2 Performs a debug attach, using %1 as the process ID to attach to and %2 as the event ID for that process. It can be used manually, but is used mostly for Just in Time debugging.
td    TDGoodies. Implements several features found in the TurboDebugger, TD32. It must be used with the d option. It causes the CPU and FPU views to stay open when a process terminates. It causes Run|Program Reset to terminate the current process and reload it in the debugger. If there is no current process, Run|Program Reset reloads the last process that terminated. It also causes breakpoints and watches to be saved in the default desktop if desktop saving is on and no project is loaded.
sddirectories   Source Directories. Must be used with the d option. The argument is either a single directory or a semicolon delimited list of directories which are used as the Debug Source Path setting (can also be set using the Project|Options|Directories/Conditionals option page). No space is allowed between sd and the directory list argument.
hhostname      Hostname. Must be used with the d option. When specified, a remote debug session is initiated using the specified host name as the remote host to debug on. The remote debug server program must be running on the remote host.
Project options
Option     Description
   filename  (No preceding dash) The specified filename is loaded in the IDE. It can be a project, project group, or a single file.
   b     AutoBuild. Must be used with the filename option. When specified, the project or project group is built automatically when the IDE starts. Any hints, errors, or warnings are then saved to a file. Then the IDE exits. This facilitates doing builds in batch mode from a batch file. The Error Level is set to 0 for successful builds and 1 for failed builds. By default, the output file has the same name as the filename specified with the file extension changed to .err. This can be overridden using the o option.
    m    AutoMake. Same as AutoBuild, but a make is performed rather than a full build.
    ooutputfile      Output file. Must be used the b or m option. When specified, any hints, warnings, or errors are written to the file specified instead of the default file.
 Generated files
Delphi generates other files in conjunction with maintaining and compiling your project, most of which you never need to consider. However, you should not delete these files. These include the following:
  File or Extension    Description
cfg  Project configuration file. Stores project configuration settings. It has the same name as the project file, but with the extension .cfg.
The compiler searches for a dcc32.cfg in the compiler executable directory, then for dcc32.cfg in thecurrent directory, and then finally for projectname.cfg in the project directory. You can therefore type:
dcc32 project1
on the command line and compile the project with all the same options as specified in the IDE. You can also type:
  make -f projectgroup1.bpg
to make all the targets in the project group.
dci   Holds Code Insight changes you make in the IDE.
dct   Holds component template changes you make in the IDE.
dmt  Holds changes you make to menu templates in the IDE (may cause a "Stream Read Error" if corrupt; deleting it will lose your changes to menu templates but resolve the error).
dof  Delphi options file. Contains the current settings for project options, such as compiler and linker settings, directories, conditional directives, and command-line parameters. Set these options using the Project Options dialog box (Project|Options), they are saved in text form for easy maintenance, version control, and sharing.
dro  Holds changes when items are added to the repository. Can be deleted but your additions to the repository will lost. Can be restored to default by copying the original file ../bin/delphi32.dro from the product CD.
dsk  Desktop settings. Saves the current state of the desktop, such as which windows are open, and in what positions. Used when Tools|Environment Options|Preferences Autosave Desktop is checked. Depending on where you working, you save desktop settings for the project (Project.dsk), project group (Group.dsk), or IDE (.dsk). Delete these if you do not want to save the desktop settings.
res   Contains the version info resource (if required) and the application main icon. This file may also contain other resources used within the application but these are preserved as is. Do not delete this file if your application contains any references to it.
tds   Holds the external debug symbol table.
todo To-do list file. Includes the current to-do list for the project. It has the same name as the project file, but with the extension .TODO.
原创粉丝点击