Delphi项目编译错误:包 ‘A’ 和 ‘B’ 都包含单元 ‘C’

huangapple go评论94阅读模式
英文:

Delphi project compilation error: Packages 'A' and 'B' both contain unit 'C'

问题

Sales项目中,存在一个名为Customers.pas的单元。Inventory项目有一个名为Products.pas的单元,它从Sales项目导入了CustomersOrders项目在Orders.dpk文件的requires子句中列出了SalesInventory,并且Customers也在OrdersUnit中导入。

然而,当我尝试编译项目时,我收到以下错误信息:

[dcc32 Error] Orders.dpk(42): E2199 Packages 'Sales' and 'Inventory' both contain unit 'Customers'

可能导致此错误的原因是什么,以及可能的解决方案是什么?我不能移动、删除或重命名代码库中的任何文件。

英文:

I have a Delphi project group consisting of three projects: Sales, Inventory, and Orders.

In the Sales project, there is a unit called Customers.pas. The Inventory project has a unit called Products.pas that imports Customers from the Sales project. The Orders project has both Sales and Inventory listed in the requires clause of the Orders.dpk file, and Customers is also imported in the OrdersUnit.

However, when I try to compile the project, I get the following error:

> [dcc32 Error] Orders.dpk(42): E2199 Packages 'Sales' and 'Inventory' both contain unit 'Customers'

What could be causing this error, and what is the possible solution? I cannot move, delete or rename any files in the codebase.

答案1

得分: 3

从错误信息明显可以看出,销售和库存模块都链接到了它们自己的Customers单元的副本,尽管您声称“库存项目...从销售项目导入Customers”。

因此,当订单项目链接了这两个包时,它最终拥有两个独立的Customers单元的副本,这是不允许的。

Customers单元必须只在一个包中实现。希望在运行时的同一进程中使用该单元的任何其他项目必须从该包中导入该单元。

您的库存项目明显没有正确地导入Customers单元。例如,如果从销售项目编译的Customers.dcu位于库存项目的搜索路径上,编译器将在编译库存项目时使用该DCU,而不是从销售包中导入该单元。确保这种情况不会发生。

英文:

It is clear from the error that the Sales and Inventory packages are both linking in their own copies of the Customers unit, despite your claim that "The Inventory project ... imports Customers from the Sales project".

As such, when the Orders project links in both packages, it ends up with 2 separate copies of the Customers unit, which is not allowed.

The Customers unit MUST be implemented in a single package only. Any other projects that want to use that unit in the same process at runtime MUST import that unit from that package.

Your Inventory project is clearly not importing the Customers unit correctly. For instance, if Customers.dcu that is compiled from the Sales project is visible on the search path for the Inventory project, the compiler will use that DCU while compiling the Inventory project, instead of importing the unit from the Sales package. Make sure that is not the case.

huangapple
  • 本文由 发表于 2023年2月24日 03:43:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75549613.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定