简体   繁体   English

为何编译器将不属于当前软件包的DCU放置在其单元输出目录中?

[英]Why does the compiler place DCUs that do not belong to the current package in its unit output directory?

I created two packages, P1.dproj and P2.dproj . 我创建了两个软件包P1.dprojP2.dproj

I put two empty units into the packages, so that P1 contains Unit1.pas and P2 contains Unit2.pas . 我在包中放入了两个空单元,因此P1包含Unit1.pasP2包含Unit2.pas

I edited the unit output directory to .\\P1\\$(Platform)\\$(Config) and .\\P2\\$(Platform)\\$(Config) in the respective packages. 我将单位输出目录分别编辑为.\\P1\\$(Platform)\\$(Config).\\P2\\$(Platform)\\$(Config)

I added P1 as a reference to the P2 project, so that P2 depends on P1. 我添加了P1作为对P2项目的引用,因此P2依赖于P1。

The project files are stored in the same folder. 项目文件存储在同一文件夹中。

The directory structure looks like this: 目录结构如下所示:

  Root\
    Source\
      P1\
        Unit1.pas
      P2\
        Unit2.pas
    Packages\
      P1.dpk
      P1.dproj
      P2.dpk
      P2.dproj
      P1\
        Win32\
          Debug\
      P2\
        Win32\
          Debug\

Before I added the dependency P1 was outputting a Packages\\P1\\Win32\\Debug\\Unit1.dcu and P2 was outputting a Packages\\P21\\Win32\\Debug\\Unit2.dcu . 在添加依赖项之前,P1输出的是Packages\\P1\\Win32\\Debug\\Unit1.dcu ,P2输出的是Packages\\P21\\Win32\\Debug\\Unit2.dcu

Nothing unexpected. 没什么意外的。

After I added the dependency when I just build P2 the IDE automatically compiles P1 as well, but the Unit1.dcu file is now outputted into the Packages\\P2\\Win32\\Debug\\Unit1.dcu . 在我刚构建P2时添加依赖项之后,IDE也会自动编译P1,但是Unit1.dcu文件现在输出到Packages\\P2\\Win32\\Debug\\Unit1.dcu

Why is that? 这是为什么?

The Unit1.dcu file is not in the Contains list of P2.droj nor is it listed in any library path or browsing path (neither Delphi global nor project local). Unit1.dcu文件不在Contains列表P2.droj也不是在任何库路径或浏览路径中列出(既不是德尔福全球也不项目地方)。

Why does the compiler put stuff into the unit output directory of the current project that it does not even have access to the source directory of? 为何编译器将内容放入它甚至无法访问其源目录的当前项目的单元输出目录中?

When I move the P1 dpk/dproj files away into some sub folder and restart the IDE it will correctly complain that it can not find the P1.dcp file and not start to compile anything from P1. 当我将P1 dpk / dproj文件移到某个子文件夹中并重新启动IDE时,它将正确地抱怨它找不到P1.dcp文件,并且无法开始从P1编译任何内容。

I had noticed this behaviour in a bigger, more complicated setup and it was driving me crazy ... 我在更大,更复杂的设置中注意到了这种行为,这让我发疯了...

It's doing this because the source files for both packages are in the same directory and P1 is set for "Rebuild as needed" in it's Project options. 这样做是因为两个软件包的源文件都在同一目录中, 并且在Project选项中将P1设置为“根据需要重建”。

Think about a simple project Proj1 that contains and uses a unit U1. 考虑一个包含并使用单元U1的简单项目Proj1。 U1 uses U2 which is not included in Proj1. U1使用包含在Proj1中的U2。 The compiler must be able to see U2.dcu; 编译器必须能够看到U2.dcu。 probably in the current Library path or some other common "lib" directory. 可能在当前“库”路径或其他一些常见的“ lib”目录中。 When Proj1 is compiled, U1.dcu goes into Proj1's unit output directory but U2.dcu is simply "used" from wherever it currently lives and does not appear in Proj1's unit output directory. 编译Proj1时,U1.dcu进入Proj1的单位输出目录,但是U2.dcu只是从当前所在的位置“使用”,并且不会出现在Proj1的单位输出目录中。

Now, suppose you add the directory where U2.pas exists to Proj1's search path. 现在,假设您将U2.pas所在的目录添加到Proj1的搜索路径中。 Now the compiler can see U2.pas, so it compiles it and places the resulting U2.dcu into Proj1's unit output directory along with U1.dcu 现在,编译器可以看到U2.pas,因此对其进行编译并将生成的U2.dcu与U1.dcu一起放入Proj1的单位输出目录中

It's the same thing here...P2 "requires" P1. 这是同一件事... P2“需要” P1。 That is, when compiling P2, the compiler needs to see either P1.DCP or all of the source files for P1 (P1.dpk and unit1.pas in this case). 也就是说,在编译P2时,编译器需要查看P1.DCP或P1的所有源文件(在这种情况下为P1.dpk和unit1.pas)。

In your case, it can see P1.dpk because it's in the same directory, so it compiles it and places the resulting dcu's (unit1.dcu in this case) into P2's unit output directory. 在您的情况下,它可以看到P1.dpk,因为它位于同一目录中,因此它将对其进行编译并将生成的dcu(在本例中为unit1.dcu)放入P2的单元输出目录。

You can prevent this behavior by setting P1 to "Explicit Rebuild" in it's project options. 您可以通过在项目选项中将P1设置为“显式重建”来防止此行为。 When building P2 or any package that "requires" P1, this tells the compiler "even though you can see P1's source, do not build it." 当构建P2或“需要” P1的任何软件包时,这告诉编译器“即使您可以看到P1的源代码,也不要构建它”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Delphi:如果我在我的项目中使用包,为什么“使用调试 DCU”变得无效? - Delphi: Why does “use debug DCUs” become ineffective if I'm using packages in my project? Delphi编译器指令列表,我们是否必须在单元名称之前放置指令? - Delphi compiler Directive list, do we have to place directives before the unit name? 有没有办法在不包含系统单元的情况下启用调试DCU? - Is there a way to enable Debug DCUs without including the System unit? 在 Indy Package 的项目选项中更改编译器 Output 位置会损坏其 DPK 文件 - Changing Compiler Output Locations in Project Options for Indy Package corrupts its DPK file 如果单元不属于项目,Delphi Help Insight不可用? - Delphi Help Insight not avalaible if unit does not belong to project? 为什么LoadLibrary成功或失败取决于当前目录? - Why does LoadLibrary succeed or fail depending on the current directory? Delphi“输出单元依赖信息” - 它有什么作用? - Delphi 'Output unit dependency information' - what does it do? 软件包的BPL转到错误的软件包输出目录 - BPLs of packages go to wrong package output directory Delphi - 定位编译器无法在其默认路径中搜索的单元的路径 - Delphi - locating path of a unit which the compiler can not search in its default path 为什么Delphi编译器没有内联汇编函数? - Why Delphi compiler does not inline assembly functions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM