Why Delphi does not output the DCU files in the correct folder?
Asked Answered
D

3

5

I have a project (C:\Test\Test.dpr) that uses a file (External.pas) belonging to library (MyLib.DPK). All files in the library are accessible via 'Search' path but I also included External.pas directly in my DPR file:

program Test;

uses
  External in '..\Packages\MyLib\External.pas',   <------ the 'external' file
  FormMain in 'FormMain.pas' {frmMain};

For this project I set the 'Output directory' and 'Output DCU dir' to ".\$(Platform)_$(Config)".

When I compile, the exe file all DCUs of this project are written in the correct output folder: c:\Test\Win64_Debug\

However, the External.dcu is generated in ..\Packages\MyLib\External.dcu
instead of c:\Test\Win64_Debug\

Why is that?


Let me ask the question in a different way: if to a DPR project I append a PAS file that is in a different folder, shouldn't all DCU files (including the external file) be generated in the same folder as the EXE file?

Delwin answered 18/10, 2015 at 15:25 Comment(8)
Is it because you use absolute path?Darkness
Actually, in my project I DO NOT use absolute paths. I show absolute paths here in order to simplify the example. Any anyway, I don't see why Delphi won't accept absolute paths :)Delwin
How about you show the real code pleaseDarkness
Until now I compiled for Delphi32 only and I let Delphi to output the DCU files in the same folder as the PAS files. I worked like a charm for many years. But now I want to compile for 64 bit so I need to use the $Platform $Config 'magic' to separate the DCUs.Delwin
Let me ask the question in a different way: if to a project I append a PAS file that is in a different folder, shouldn't the DCU file be generated in the same folder as the EXE file?Delwin
Is it wrong to use .\$(Platform)_$(Config) instead of .\$(Platform)\$(Config) ? I don't think so....Delwin
The DCU files are placed in the Unit Output Directory, while the EXE is placed in the Output Directory. So they are not necessarily in the same folder.Bathhouse
Damn it... I did it again... I set the Traget for 'All configurations - All Platforms' but the path for 'Debug config-64bit windows platform' was already set to something else (similar as path to the other configurations). So, when I set the correct path in 'All configurations', the 'Debug config-64bit windows platform' left as it was. I have 12 possible configurations (debug, release, pre-release) so I haven't seen that 'Debug config-64bit windows platform' is set to something wrong. The GUI for Project Options can cause lots of mistakes!Delwin
D
6

From the documentation:

Output directory

Specifies where the compiler should put the executable file.

Unit output directory

Specifies a separate directory to contain the compiled units (.dcu).

It sounds like you need to specify the unit output directory as well as the output directory. Personally I tend to keep these two directories separate.

Darkness answered 18/10, 2015 at 16:2 Comment(0)
L
4

Yes the Project Options UI can be quite confusing especially because in order to access settings for each target platform you need to switch to that target platform via the dropdown list.

This part of the IDE could be made much better if you could simply see configurations for all target platforms at once.

Now if you want to be able to maintain output paths setting on one location (All configurations) you just need to make sure that specific target configurations are not overriding it.

To do so go to specific target configuration and then instead of clicking on the field entry itself click on the + sign in front of it.

This will expand current property field and also show the values from parent configurations from which this property can be inherited from.

Project Options

NOTE: While many properties can indeed be inherited (property values from target configuration are added to properties from parent scheme like) Output directory and Unit output directory since they can contain only one value are simply overridden.

So in order to make sure that output locations from All configurations is used in every specific target configurations none of them should not have defined custom value for output locations.

In other words values from Release configuration - ... or Debug configuration - ... when you have specific property expanded must be empty like in the picture above.

Livy answered 18/10, 2015 at 17:39 Comment(1)
also you can do the same by adding to your *.dproj file the following: <PropertyGroup> <DCC_DcuOutput>.\lib\$(Platform)\$(Config)\</DCC_DcuOutput> </PropertyGroup>Pucka
D
2

Damn it... I did it again... I set the Target for 'All configurations - All Platforms' but the path for 'Debug config-64bit windows platform' was already set to something else. So, when I set the (correct) path in 'All configurations', the 'Debug config-64bit windows platform' remained as it was. I have 12 possible configurations (debug, release, pre-release) so I haven't seen that 'Debug config-64bit windows platform' remained set to the original value. The GUI for Project Options can cause lots of mistakes!

Thanks David. Sorry for wasting your time. I am still struggling with Delphi paths. There is nothing in the whole IDE as confusing/weird as the paths (search, output, library, etc)

Delwin answered 18/10, 2015 at 16:1 Comment(2)
I suppose the IDE is trying to do its best of an awkward job, supporting multiple build targets. Have you looked into Option Sets? I thought they might help with stuff like this, but didn't get very far, personally.Pavonine
Option sets aren't really useful for this scenario, I don't think. They are useful, just not here. Delphi does a far better job in this area than VS, by supporting inheritance. Yes, it's complicated. But once you get it right, it is very powerful and flexible.Darkness

© 2022 - 2024 — McMap. All rights reserved.