title: Delphi package problem : Packaged units must refer only to packaged units.. (E2411)
body: <p>The error I get is like this:</p>
  
  <p><code>[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</code></p>
  
  <p>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).</p>
  
  <p>Such problems involve package dependencies.  I am having an interesting problem with a series of three designtime and three runtime packages related like this:</p>
  
  <p><img src="https://i.stack.imgur.com/yV7Nd.png" alt="enter image description here"></p>
  
  <p>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).</p>
  
  <p>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.</p>
  
  <p>Steps;</p>
  
  <ol>
  <li>Compile A, it works.</li>
  <li>Compile A_Dsgn, it works.</li>
  <li>Compile B, it Works.</li>
  <li>Compile B_Dsgn, it works.</li>
  <li>Compile C, and it fails with this E2411 error.</li>
  </ol>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p><strong>Update</strong>  I tried playing with the <code>Explicit Rebuild</code> and <code>Rebuild as Needed</code> 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 <code>Rebuild as needed</code>.  Any ideas what is going on?</p>
  
  <p><strong>Update 2</strong> 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?).</p>