英文:
Delphi project compilation error: Packages 'A' and 'B' both contain unit 'C'
问题
在Sales
项目中,存在一个名为Customers.pas
的单元。Inventory
项目有一个名为Products.pas
的单元,它从Sales
项目导入了Customers
。Orders
项目在Orders.dpk
文件的requires
子句中列出了Sales
和Inventory
,并且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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论