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

207 views Asked by At

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

There are 1 answers

2
Remy Lebeau On

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.