Originale-mail to me for new edition

 

Compiler-generated files

 

The first time you build an application or a standard dynamic-link library, the compiler produces a compiled unit .dcu (Windows) .dcu/.dpu (Linux) file for each new unit used in your project; all the .dcu (Windows) .dcu/.dpu (Linux) files in your project are then linked to create a single executable or shared library file. The first time you build a package, the compiler produces a .dcu (Windows) .dpu (Linux) file for each new unit contained in the package, and then creates both a .dcp and a package file. (For more information about libraries and packages, see Libraries and packages.) If you use the $D switch, the linker generates a map file and a .drc file; the .drc file, which contains string resources, can be compiled into a resource file.

When you rebuild a project, individual units are not recompiled unless their source (.pas) files have changed since the last compilation, or their .dcu (Windows) .dcu/.dpu (Linux) files cannot be found, or you explicitly tell the compiler to reprocess them. In fact, it is not necessary for a unit’s source file to be present at all, as long as the compiler can find the compiled unit file.

 

Topic groups

Using Object Pascal

Program organization: Overview

Pascal source files

Other files used to build applications

Compiler-generated files

About example programs

A simple console application

A more complicated example

A native application

 

See also

Other files used to build applications

Pascal source files

 

 

译文

 

编译器产生的文件

 

首次建立应用程序或标准动态链接库时,编译器将为工程中每个新引用的单元产生编译过的单元.dcuWindows)文件或.dpuLinux)文件;工程中所有.dcuWindows)或.dpuLinux)文件将被连接用于创建一个单独的可执行文件或可共享的库文件。首次建立包时的情况也类似,不同的是,首次建立包时,编译器还要产生一个包(.dpk)文件和一个编译过的包(.dcp)文件。(关于库和包的更多信息,见库和包。)如果使用了$D编译指示,连接器(linker)还将产生一个映象文件和一个.drc文件。其中,.drc文件中含有字符串资源,可以被编译成为资源文件。

重建工程时,部分单元不会被重编译,除非其源文件(.pas文件)自最后一次编译以来发生了改变,或者不能找到相应的.dcuWindows)文件或.dpuLinux)文件,或者明确让编译器重新编译。实际上,根本不必为编译器提供单元的源文件,只要编译器能找到相应编译过的单元文件即可。

 

主题组

使用Object Pascal

程序组织:概述

Pascal源文件

用于建立应用程序的其他文件

编译器产生的文件

关于范例程序

简单的控制台应用程序

相对复杂的范例

本地应用程序范例

 

相关主题

用于建立应用程序的其他文件

Pascal源文件

 

 

编者注

可以将编译过的单元(.dcu)文件视为静态链接库(区别于动态链接库)。使用Object Pascal编程时,通常为了使程序组织清晰明了而将源代码分布到相对独立的单元(unit)中去。例如,Delphi提供的VCL库中就有专门定义常量的单元Consts.pas。对于已经完成的单元,可以将其源代码归档,而只保留.dcu文件。这样做至少会有两个方面的好处:一方面在团队开发中可以保证单元的一致性,即源代码由归档者专门维护,而将编译产生的.dcu文件分发给其他开发者使用;另一方面是可以做到只提供功能而不提供源代码,从而保护源代码编写者的技术,这一点对于商业应用尤其重要。例如,Delphi提供的VCL组件和其他大量的可利用的编程资源,都是以.dcu文件的形式提供给开发者直接利用。尽管同时也提供了几乎全部的.pas源文件,但Delphi不会对其进行编译,而是直接连接既有的.dcu文件。这样就避免了开发者改变源文件后可能带来的意外情况。与此同时,Delphi对于某些特别的单元,如支持报表组件(据说是第三方提供的)的所有单元,都没有提供源文件(与此情况相同的还有Jpeg单元等)。

DelphiKylix都是基于Object Pascal语言的快速应用开发(RAD)工具包,二者的区别在于前者基于Windows操作系统,后者基于Linux操作系统。因此,在某些文件的命名上有所区别,尽管从程序组织方面可以认为是等同的。还有一个重要原因是,Delphi 6可以建立跨平台应用程序,因此需要在命名上与基于Windows的应用有所区别,毕竟Object Pascal中的一些特性对Linux操作系统是不支持的,如自动化对象(Automation Object)、双重接口(Dual Interface)等。