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

Frazz picture Frazz · Jan 22, 2015 · Viewed 16.9k times · Source

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.

Answer

kludg picture kludg · Jan 22, 2015

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).