Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi compile error F2048 Bad unit format

Tags:

delphi

I ran into an obscure error and am posting the solution here in the hope that it will help someone else having the same problem.

I am writing a Continuous Integration (CI) program using Delphi XE4 to ensure that a set of pascal source files will compile under older versions of Delphi. This CI program runs a series of batch files each running the command line compiler of an older Delphi version. The batch file running the XE compiler produced the following error:

F2048 Bad unit format: 'c:\program files (x86)\embarcadero\rad studio\11.0\lib\Win32\release\System.dcu' - Expected version: 22.0 ... Found version: 25.0

Note that the expected and found versions are different (in this case XE and XE4). Several people have reported similar errors where the expected and found versions were the same - this is usually a mixup between 32 and 64 bit DCUs, but that wasn't the problem here.

This problem only occurs when the CI program is run from within the Delphi XE4 IDE. If the CI program is run outside of the IDE it works fine.

like image 232
David Hawk Avatar asked Jan 03 '17 23:01

David Hawk


1 Answers

The XE4 IDE adds several environment variables that are inherited by the program being debugged (in this case CI) that are in turn inherited by the batch files. One of these extra environment variables confuses the XE compiler when run in the batch file. The culprit is the added BDSLIB environment variable that points to the XE4 lib directory.

The solution was to simply add

set BDSLIB=

to the beginning of each of batch files. Once this change was made the CI program runs successfully both inside and outside the IDE.

like image 132
David Hawk Avatar answered Sep 30 '22 14:09

David Hawk