0

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.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Zarik
  • 65
  • 6

1 Answers1

3

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.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • To be honest, I have simplified the scenario to these 3 projects. The actual project group is legacy code base of a twenty something years old product and there are several other projects inside the project group which has the Inventory in their requires list. I am 100% sure that there is no Customers unit in the Inventory project and the only project which contains the Customers.pas is the Sales. – Zarik Feb 24 '23 at 12:38
  • @Zarik "*there is no Customers unit in the Inventory project*" - in your question, you said: "*The Inventory project has a unit called Products.pas that imports Customers from the Sales project*". Clearly that import is not working correctly. The compiler is pulling in the Customers unit from somewhere else. Just because Sales doesn't contain the PAS file doesn't mean it can't use the DCU file. Try using [SysInternals Process Monitor](https://learn.microsoft.com/en-us/sysinternals/downloads/procmon) to see which files the compiler is actually touching while compiling. – Remy Lebeau Feb 24 '23 at 18:25