Error F2063 Could not compile used unit (of dependent package)

16,453

Delphi IDE is far from perfect when it comes to editing/compiling packages but you should solve the problem on your side - configure your packages better and Delphi will compile them correctly.

I can only give you general advices addressing the info given:

  • If you need a common include file for 2 packages create a separate directory for the file and add this directory to the search paths of both packages (in Base build configuration).

  • Never keep .dcu's in the same folders with source files; always set "unit output directory" option for your packages (also in Base build configuration); I recommend $(BDSCOMMONDIR)\MyPacks\$(Config)\$(Platform) as such directory for your packages; if you already have .dcu's in the source (.pas) folders delete them, does not matter which Delphi version created these .dcu's.

  • Never add paths to dependent package's sources to the search path, only paths to compiled .dcu's (would be $(BDSCOMMONDIR)\MyPacks\$(Config)\$(Platform) if you follow previous advice).

Share:
16,453
Frazz
Author by

Frazz

I've started programming when I was 12... and that was way back when computers did not have monitors... over 35 years ago. That actually means I'm old :( Basic, C, ObjectPascal (aka Delphi), Java, JSP, PHP... I've tried a lot of languages and I still like to learn some new tricks. I've mostly worked on databases, client-server and multi-tier applications. I've also done some years on data warehouses, especially in SAS. I now live in Italy, but I spent some years in England and in the States... and that is where I picked up my only sport passion... baseball :)

Updated on June 04, 2022

Comments

  • Frazz
    Frazz almost 2 years

    I have written 2 packages: MEComps_DXE5 and AMLComps_DXE5. The latter depends on the former. Both should be multi-platform: Win32, Win64, and (in the future) OSX.

    When I open the first package MEComps_DXE5, I am able to compile it, build it and install it. I get some warnings, as this library contains code that must also compile on old D5, but the build succeeds and creates the dcu and dcp files where expected.

    When I open the second package AMLComps_DXE5, I find this situation:

    • If I do not declare the dependency on MEComps_DXE5, the package will compile and build correctly (no errors, dcu and dcp files are generated), but Delphi will warn me that it has implicitly imported units from MEComps_DXE5, and ask me to add the package to the dependency list (Requires)
    • If the dependency is declared, then the compilation will fail with "[dcc32 Fatal Error] MEComps_DXE5.dpk(52): F2063 Could not compile used unit 'MEClasses.pas'", where MEClasses is the first unit of the MEComps_DXE5 package.

    I've been trying to solve this for a few days now, but to no avail. I'm working on two fronts:

    • Why is Delphi even trying to compile the other package? I have just built and installed it, and have all dcus and the dcp.
    • Why is the compilation failing?

    As to the first question I have no clue whatsoever.

    As to the second question, the documentation is useless in this case. It explains why not being able to compile a used unit is fatal, and states that the cause is determined by looking at the previous errors. But in this case, there are NO previous errors.

    As MEComps_DXE5 actually compiles and builds on its own, I doubt this has anything to do with syntax or code. It would seem to be that the compiler is not able to find something it needs to compile those units.

    The two packages reside each in their own directory. I put the MEComps\Win32 dcu directory on the library path and on the browsing path. The IDE actually has no problems looking up the used units.

    I also checked the dcc32 command line and it seems that all envolved directories are known to the compiler.

    Other info I can add:

    • Both packages have their own include file (in their source directory). I'm not sure if these are to be included in the package contains list or not, but I've tried both ways and nothing seemed to change.
    • Both packages have a corresponding Delphi 5 package which includes some of the same units and code (different dpk though). These compile and build correctly. Delphi 5 dcu files are generated in the source directory. Can this create problems with the XE5 compiler?
    • Here is the complete code for the MEComps_DXE5 package. I see a lot of compiler directives that Delphi inserted when it created the empty package. I didn't touch those:

            package MEComps_DXE5;
    
        {$R *.res}
        {$IFDEF IMPLICITBUILDING This IFDEF should not be used by users}
        {$ALIGN 8}
        {$ASSERTIONS ON}
        {$BOOLEVAL OFF}
        {$DEBUGINFO ON}
        {$EXTENDEDSYNTAX ON}
        {$IMPORTEDDATA ON}
        {$IOCHECKS ON}
        {$LOCALSYMBOLS ON}
        {$LONGSTRINGS ON}
        {$OPENSTRINGS ON}
        {$OPTIMIZATION OFF}
        {$OVERFLOWCHECKS OFF}
        {$RANGECHECKS OFF}
        {$REFERENCEINFO ON}
        {$SAFEDIVIDE OFF}
        {$STACKFRAMES ON}
        {$TYPEDADDRESS OFF}
        {$VARSTRINGCHECKS ON}
        {$WRITEABLECONST OFF}
        {$MINENUMSIZE 1}
        {$IMAGEBASE $400000}
        {$DEFINE DEBUG}
        {$ENDIF IMPLICITBUILDING}
        {$IMPLICITBUILD ON}
    
        requires
          rtl,
          fmx,
          dbrtl,
          xmlrtl;
    
        contains
          MEClasses in 'MEClasses.pas',
          MEConsts in 'MEConsts.pas',
          MEDataReader in 'MEDataReader.pas',
          MEDateUtils in 'MEDateUtils.pas',
          MEEncoding in 'MEEncoding.pas',
          MEEncodingISO2022 in 'MEEncodingISO2022.pas',
          MEFileUtils in 'MEFileUtils.pas',
          MELists in 'MELists.pas',
          MEMath in 'MEMath.pas',
          MENumUtils in 'MENumUtils.pas',
          MESQLUtils in 'MESQLUtils.pas',
          MEStrUtils in 'MEStrUtils.pas',
          MESysUtils in 'MESysUtils.pas',
          METypes in 'METypes.pas',
          MEURIUtils in 'MEURIUtils.pas',
          MEXMLUtils in 'MEXMLUtils.pas';
    
        end.
    

  • Frazz
    Frazz over 9 years
    I'll have a look at this advice. The dcu I have in the source directory are the Delphi 5 ones. Delphi XE5's are in the standard config\platform subdirectory. As to the last point though, are you saying I should put the source directory in the Browsing path, but not in the Library path?
  • kludg
    kludg over 9 years
    Neither. Library path is for .dcu's but I prefer not to use it at all; Browsing Path is for sources but it is used by the IDE editor, not by the compiler.
  • kludg
    kludg over 9 years
    All you need to compile the packages is to set "search path" and "unit output directory" options of your packages.
  • Frazz
    Frazz over 9 years
    I accepted this answer as separating the sources from the dcus seems to have done the trick. Not having the sources on the library path is a bit of a PITA though, as I always risk to debug dcu that does not match the sources and I have to build and install the package even just to run the unit tests :(