Delphi Compile and Build 在同一个项目上生成不同的二进制文件 [英] Delphi Compile and Build produce different binary on same project

查看:14
本文介绍了Delphi Compile and Build 在同一个项目上生成不同的二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在新的 VCL 应用程序中 编译构建 操作生成相同的二进制文件和映射文件(即使包含版本信息",.exe 文件末尾也有细微差别在项目中"选项已关闭 - 已经讨论过).映射文件是相同的字节到字节.但是我添加任何第三方组件后,Build 和 Compile 生成的二进制文件和 map(!) 文件明显不同!

In a fresh VCL application Compile and Build operation produce the same binary and map file (with minor differences at the end of .exe file even if "include version information in project" option is switched off - already discussed). Map file is the same byte to byte. But wen I add any third-party component the binary and map(!) file produced by Build and Compile are significantly different!

在两个版本的 Delphi 上测试:
- 7.0 版(内部版本 8.1)
- CodeGear™ RAD Studio 2007 版本 11.0.2902.10471(+2007 年 12 月更新)

Tested on two versions of Delphi:
- Version 7.0 (Build 8.1)
- CodeGear™ RAD Studio 2007 Version 11.0.2902.10471 (+December 2007 Update)

重现步骤:

  1. 创建新的 VCL 应用程序.可能添加任何原生 Delphi 组件(我尝试了标准、附加、Win32 和系统选项卡中的所有组件).
  2. 在项目选项的链接器选项卡上打开详细地图文件.
  3. 构建项目.
  4. 重命名输出 .exe 和 .map 文件(例如:project1.exe 为 project1b.exe,project1.map 为 project1b.map).
  5. 编译项目.
  6. 重命名输出 .exe 和 .map 文件(例如:project1.exe 为 project1c.exe,project1.map 为 project1c.map).
  7. 比较第 4 步和第 6 步中的文件.(我使用 WinMerge2.12.4.0).

我们几乎没有不同的 .exe 文件和完全相同的 .map 文件.然后如果我们再次重复所有步骤,但在项目中使用第三方组件(我尝试了 ODAC、DOA、DevExpress 和自制),我们会得到更多不同的 .exe 和不同的 .map 文件.

We have little different .exe files and fully identical .map files. Then if we repeat all steps again but use in the project third-party component (I try ODAC, DOA, DevExpress and selfmade) we get more different .exe and different .map files.

为什么?有什么建议吗?

Why? Any suggestions?

更新
关于我是如何发现这个的以及为什么我对它感兴趣的一些信息:
项目是使用 MSBuild 从简单脚本构建的.当在项目中通过 ITE(带有资源的 dll)添加翻译时,我发现当项目构建时(来自脚本或来自 IDE) - 翻译版本工作错误 - 按钮、标签等上的一些文本来自错误的地方(字面意思是来自另一个按钮、标签).当项目从 IDE 编译时 - 一切正常.所以我开始比较 Build 和 Compile 输出...

UPDATE
Some information about how I found this and why it's interests me:
Project is build from simple script with MSBuild. When in the project was added translation thru ITE (dll with resources) I found that when project was Build (from script or from IDE) - translated version work wrong - some text on button, labels etc. got from wrong place (literally from another button, labels). When project Compiled from IDE - everything is ok. So I start compare Build and Compile output...

推荐答案

您所看到的只是编译器内置 make 逻辑的产物.当您进行构建时,它会告诉编译器构建所有可用的源.因此,Delphi 处理每个源文件,并针对它找到源的使用列表中的每个单元,然后构建该文件.它递归地执行此操作.当您进行编译时,只会加载现有的 .dcu 文件,如果发现它们是最新的,则不会执行任何操作.这实际上会导致单位被发现的不同顺序,因为每个 .dcu 将有效地扁平化"使用列表.由于单位以不同的顺序被发现和加载,它们依次以不同的顺序链接.这就是您的地图文件看起来如此不同的原因.给定相同的来源,如果您连续进行两次构建或连续进行两次编译,映射文件应该相同.

What you're seeing is simply an artifact of the built-in make logic of the compiler. When you do a build, it tells the compiler to build all available sources. So Delphi processes each source file and for each unit in the uses lists for which it finds source, it will then build that file. It does this recursively. When you do a compile, only the existing .dcu files are loaded and if they're found to be up-to-date, nothing is done. This can actually lead to a different order in which the units are discovered since each .dcu will effectively "flatten" the uses list. Since the units are discovered and loaded in a different order, they are in-turn, linked in a different order. This is why your map files look so different. Given the same sources, the map file should be the same if you do two builds in a row or two compiles in a row.

导致差异的其他原因更为常见,包括 PE 标头时间戳等内容,以及其他填充和对齐位.

Other causes for differences are more mundane and include things like the PE header time stamp, and other bits of padding and alignments.

这篇关于Delphi Compile and Build 在同一个项目上生成不同的二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆