6
votes

The error I get is like this:

[DCC Fatal Error] myunit3.pas(244): E2411 Unit XBAT in package B_Dsgn refers to unit QBEE which is not found in any package. Packaged units must refer only to packaged units

I need to know what this error I am encountering really means, and if possible how to troubleshoot and solve such problems, especially when the facts stated in the error message are not correct (the units are in fact referring to other units in other valid packages).

Such problems involve package dependencies. I am having an interesting problem with a series of three designtime and three runtime packages related like this:

enter image description here

What is most odd about it is that each time I clean and rebuild, I get a different unit name in the error. (Shown above as Unit XBAT refers to unit QBEE).

The other odd thing is that it's referring to units that are in a top level dependency, and are part of a package that was already built.

Steps;

  1. Compile A, it works.
  2. Compile A_Dsgn, it works.
  3. Compile B, it Works.
  4. Compile B_Dsgn, it works.
  5. Compile C, and it fails with this E2411 error.

Since I doubt anybody can tell me how to fix this exactly, I am looking for the steps to troubleshoot a complex dependency problem in a package. The literal meaning of the above error suggests for example, that I should have a corresponding message about an implicit linked unit, which I do not have. I have added all implicitly used units to the base packages A, and B, so that no implicit unit warnings are made.

My next idea was to separate the DCU output folders for each package, to prevent the DCU outputs from one from confusing the compiler. Now I can not even build the packages.

Update I tried playing with the Explicit Rebuild and Rebuild as Needed options. I have found that this error is related to having 'Rebuild as Needed' turned on. When it is turned off, the packages fail with other errors which are more to the point. I find it odd that the compiler emits weird errors that can be disabled by turning off Rebuild as needed. Any ideas what is going on?

Update 2 The basic underlying problem is not solved by turning on or off explicit rebuild. Instead of getting this error, I get annoying runtime/designtime package problems, which result in a set of packages, that can not be loaded at the same time. (Can not load package foo because it contains unit bar which is also in package bat. Do you want to attempt to load this package the next time a project is loaded?).

4
If I understand you correctly, when "Rebuild as Needed" is checked, then building C triggers a rebuild of B, which subsequently triggers a rebuild of B_Dsgn (which fails) - are you sure you haven't introduced some kind of circular dependency from C/C_Dsgn to B/B_Dsgn? - Frank Schmitt
Are you using weak packaging? - Ondrej Kelle
Good question.Tomorrow at work I will search for references to weak packaging. - Warren P
@TOndrej: I can't see how weak pacakging has anything to do with it. That doesn't change which unit is in which package's contains and which units are referenced. It only changes how units are linked in (either always, as part of the BPL or only when needed, copied from the .dcp file and linked in directly). - Rudy Velthuis
IMO, it is a delphi compiler bug. - stanleyxu2005

4 Answers

7
votes

I suspect it is an obscure compiler bug.

The project I experienced it in had at least 4 levels of dependent runtime packages:

PackageA <- PackageB <- PackageC <- PackageD

E2411 Unit '%s' in package PackageD refers to unit '%s' which is not found in any package. Packaged units must refer only to packaged units.

The only solution I found that worked was to make packages A, B and C never-build (i.e. Explicit Build) packages and use Project Dependencies to enforce build order instead. I had to make all three never-build or I would get

E2220 Never-build package '%s' requires always-build package '%s'

I know its probably not the answer you were looking for but there it is.

Btw, this happened to me in Delphi 2009.

2
votes

It is quite simple: If a unit in C refers to a unit not in any package referred to by package C, that unit should be included in C, or the package in which it can be found should be referenced by C. If necessary, put the unit in a package of its own.

Where you put which unit depends on the dependencies. It makes sense to draw it out, like you did, but with a unit level resolution.

Update

Your update 1 and update 2 still make me think there is a unit one of your units uses (directly or indirectly) that is not properly referenced. Perhaps even an RTL or VCL unit. Since you have design packages, I assume you have components in them.

IME, the minimum set of packages to include is

requires
  rtl,
  designide,
  vcl,
  vclactnband,
  vclx,
  xmlrtl;
1
votes

In the project that gives the error must be added as required the. dcp error.

In your case:

[DCC Fatal Error] myunit3.pas (244): E2411 Unit in package B_Dsgn XBAT Refers to unit QBEE Which is not found in Any package. Must Refer Packaged units only to packaged units

In the package where it myunit3.pas drive, add in required: QBEE

At least I managed to do so.

0
votes

You are using the QBEE unit in the unit XBAT, in this case you have foure options:

1- you didn't add the QBEE to the contains list in the Package B_Dsgn.

2- If QBEE is already containd in another Package lets call it Original_Package then you should add the Package to the requires list in B_Dsgn and not contain the unit.

3- the Original_Package has

{$IMPLICITBUILD ON}

in it's dpk file so first what you have to do is to turn IMPLICITBUILD off and build Original_Package after that you can build your B_Dsgn package.

4-you probably didn't have XBAT in B_Dsgn but you have it in another middle package lets call it B_Run and you have B_Run in the requires list of B_Dsgn, in this case try first to fix B_Run with one of the upper three options and then build it, after that you can build B_Dsgn.

Note:

  • the last two cases could be reproduced with a long list of units and not just two or three packages that are requiring each other, in this case all of the packages should have IMPLICITBUILD off.
  • Clean the code for every single package of the packages that effect the issue before building them.

good luck