The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,042 other followers

Do not share DCU files between projects (via: delphi – Compiler Directive IF and IFEND – Stack Overflow)

Posted by jpluimers on 2014/02/13

Summary: Always try to avoid sharing .DCU files between projects.

I see a lot of projects at clients that do not have their individual DCU directories set (therefore having the DCU files in the same directory as the PAS files causing shared units to share the DCU files), or share DCU files among different projects.

Both are a very bad idea, as the compiler does not always understand when the DCU file does not match the combination of PAS file and compiler options.

The result is the occasional use of the DCU file in stead of the PAS file causing wrong code to be used, or wrong debugger information to be included.

Danny Thorpe phrased it on Stack Overflow:

Note that if two projects share a compiled unit, you will need to be careful to rebuild each project when switching between them. Changing a compiler define will not be enough for the compiler to know that it needs to recompile that unit from source in order to apply the new compiler defines. It would be best if the projects did not share the DCU, but shared only the .pas source file and output the .dcu to project-local directories. – dthorpe Mar 20 at 0:24

The above underlined is one of the first things I do on projects at new clients.

This was already the case with DOS based Turbo/Borland Pascal and Turbo Pascal for Windows. Probably also the same for FreePascal and Lazarus.


via delphi – Compiler Directive IF and IFEND – Stack Overflow.

9 Responses to “Do not share DCU files between projects (via: delphi – Compiler Directive IF and IFEND – Stack Overflow)”

  1. We never had a problem when switching projects without rebuilding. But we have all DCUs separated between common units, which are prebuilt by a build script, and project specific units, which are compiled to a project, platform and build configuration (!!) specific directory as written in this article.

  2. Do you mean between projects or between delphi versions? If you mean between projects not have any sense at all. Many third party providers historically don’t provide source code, just compiled versions (dci) for some units and no problem at all. AFAIK a dci file already was compiled with all the ifdef definitions on the source code at compile time. Example:

    result := 1;
    result := 2;

    Then i build my project with RETURN1 define, the code generated inside the dcu will be return 1.

    If then i want to share that dci with another person, even if him remove the define , the code still will return1. That is wath i tested.

    For this reason i understand your post is wrong.

    Many third party set IFDEF to define trials and not trials version. If changing the define change the DCU inside, the anybody can use non trial versions with just chang e a define. So again, i believe you are wrong.

    Best regards.

    • jpluimers said

      I mean for projects with the same Delhi version, but with different conditionals defined in their .dproj files.

      That often fails when the DCU files are shared by different projects (for instance if the DCU files are in the same directory as the PAS files, or with a shared DCU directory), sometimes even when you do a rebuild.


      • Can you describe fails? Fails to build?

        I agree, have no sense to have dcus and pas on the same file. The only use i apply to dcus is to release some part of code already compiled. And yes, you will always will ned a rebuild on delphi!

        Best regards.

  3. izkacin said

    I agree, but I have learned to always do a full rebuild when I change projects. Always. Not only because of DCUs but also other potential problems.

  4. gabr42 said

    Guilty. But we have a good reason for that – all DCUs are on a RAM drive. You just have to do a rebuild after you switch projects.

  5. Except third party code. And as I see many projects (also commercial components) that don’t put dcu files into a proper location (Delphi version specify folder) this is important.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: