Delphi command line compiler - using same library path as the IDE - delphi

Is there a way to instruct DCC32 to use the same library path that is used by the IDE (i.e. in Tools/Options/Environment Options/Delphi Options/Library - Win32)?
For obvious reasons, I do not want to maintain two lists of directories (one in a cfg file, one in the Delphi IDE).

If you are using Delphi 2006 or later, you can use MSBuild instead of dcc32, and MSBuild will use the same search path as the IDE

You should have a cfg file in your project directory called yourprojectnamedpr.cfg which actually should contain all the directories defined in the IDE for that project.

It is a lot of work to use DCC32 to build from the command line. MSBuild is far easier. The library path is stored in the registry, but the location depends on the Delphi version, for example (python code):
if BDSVER == '5.0':
CompanyText = 'Borland'
else:
CompanyText = 'CodeGear'
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,'Software\\' + CompanyText + '\\BDS\\' + BDSVER + '\\Library')
IncludePath = _winreg.QueryValueEx(key,'Search Path')[0]
# Then you must replace the environment vars $(BDS), $(BDSCOMMONDOR) etc
IncludePath = ReplaceEnvironVars(IncludePath)
And there is much more to do. You must also obtain the search path, and you must obtain conditional defines from the .dproj file, etc.
I wrote a complete automated build tool in python (for BDSVER >= 5), back when Delphi 2007 installed on XP x64 had a broken MSBuild. Later, it turned out that some required configuration files were not copied into the correct .NET folder by the Delphi installer. Copying these files to the correct location fixed the problem, and now I use MSBuild.

This works for me:
call "C:\Program Files (x86)\Embarcadero\Studio\19.0\bin\rsvars.bat"
msbuild project.dproj

If you use an older Delphi (e.g. Delphi 7), you must put all your information in the "Search Path" Directory option in your IDE. It will be saved in your .dof file. The .dof file is the main reference of your project.
The IDE will also automatically update the .cfg every time you change the project configuration. The .cfg is the specifies the compilation option for the command line compiler. Both the .cfg and the .dof must be under version control.
If, instead of editing your .dof file from the IDE, you manually edit it, you can use the dof2cfg utility to generate a new .cfg from your .dof. You will have to put it in your build chain.

Related

Error: F1026 File not found: 'System.Actions.dcu' by Command Line Compiler

The editor automatically adds the System.Actions unit when one of my forms is saved.
It compiles without a problem in the IDE, but unfortunately the Command Line Compiler can not find the file and gives me the error:
Error: F1026 File not found: 'System.Actions.dcu'
What am I missing?
In what follows, I am assuming that you are using msbuild to compile your program.
The System.Actions unit was added in XE3 to support actions in both FMX and VCL frameworks. Prior to that release FMX had no actions. Some classes were moved around, out of VCL units and into the new System.Actions unit which can be used by both FMX and VCL code.
So, the compiler error that you see suggests to me that you are unintentionally compiling with a version that pre-dates this change. My guess is that your IDE is XE3 or later, but that your command line build is configured to use an earlier version of Delphi. Most likely through the PATH environment variable, and whatever Embarcadero entry happens to be first in that variable.
If my hunch is correct then you need to ensure that you compile with the desired version.
The way I organise machines that have multiple Delphi installations is as follows:
Remove all Embarcadero entries from your PATH environment variable.
Whenever you need to build at the command line, configure the environment, for instance by running the appropriate rsvars.bat script (found in the bin directory of your Delphi installation) before you call msbuild.
This way you cannot accidentally find the wrong version because you have to explicitly configure an environment.
On the other hand, perhaps you are calling dcc32 directly. Don't do that. You will have to supply all the options and paths that are already defined in your project file. Repeating that is just a way to create a maintenence headache and make it likely that your command line build won't match the IDE build.
Instead, use msbuild to build your program. That way you can use the settings defined in your project file.
Thanks Hefferman for your advice but we shall stick with dcc32. It's easier to customize. For example we didn't figure out how to use more than one 'define' parameter with msbuild. It's possible to use dcc32 with the -NS switch for dependent 'uses' and that is our solution. We also create some .dpr files with code and in that case we do not have a corresponding .dproj file.

How does Delphi 7 find all the dcu files during compilation?

I am helping a coworker set up his computer so that his Delphi 7 environment works like mine. He has Delphi 7 installed plus the third party tools we use. We have a Delphi app with source. It compiles fine on my computer but when he compiles it on his computer, it keeps coming up with 'file not found' errors for many dcu files. These are dcu files of third party components, either which come with Delphi IDE or have been installed manually.
I renamed his C:\Program Files (x86)\Borland folder and copied my whole Borland folder structure to his so that he has what I have. So now his Delphi IDE and the app structure resembles mine, yet he still gets missing dcu's. Every time he gets a missing dcu, he adds its path to Delphi's 'Search path' list. For some dcu's, they exist in different folders which means we have to troubleshoot further to make sure we picked the correct version. My 'Search Path' is empty as shown below which tells me my Delphi doesn't use this entry to search for dcu's. Our computer's PATH environment variable entry has the same values for anything related to Delphi.
My question is why my delphi app compiles fine as it finds all the dcu's it needs which reside in different folders yet his Delphi is not finding them when we have the same folder structure and PATH?
How does the Delphi IDE finds all the dcu's it needs during compilation? What is left now to look at is the registry. Are the search patterns in the registry? Where? (We also have Delphi XE installed if this means anything)
You don't want to add these directories to your project's search path. That will make it so that only this project is able to use these components. Instead, you need to do this in the global library path, which applies for all projects. Check the library path of your existing installation, surely you'll find a large list of directories here.
Main Menu -> Tools -> Environment options dialog -> Library page -> Library Path edit box
They are the output paths, try looking in the following location
Tools > Options > Environment Options > delphi Options > Paths and Directories
This tells the IDE what source files to include. The only other difference can be if you system variables are different if you have any.
http://docwiki.embarcadero.com/RADStudio/XE8/en/Library

Where can I configure DCC_ExeOutput?

Is it possible to configure DCC_ExeOutput from Delphi? I could only change this by editing the dproj file.
I couldn't find where to edit this option even using Delphi IDE Insight.
Update 1:
This is my Project Options:
#TOndrej have suggested me change output directory, but I have already done this, and DCC_ExecOutput didn't change. The only way was editing dproj file.
Update 2:
My purpose is organize the folder structure of Delphi projects like suggested by Zarco Gajic in his article How to Layout Delphi Project Files - Best Practice.
Delphi creates folders for each platform to store .dcu, .exe and other files. .\$(Platform)\$(Config) is the default for Delphi. So in the same level of .dproj Delphi creates the folders Win32, Win64, Android, etc.
As you can see in the picture above, I've configured Delphi to put those files in a better organized form, in my opinion. Below an example:
My_Delphi_Project_folder
Bin
|___Debug
| |____Win32
| |____Win64
| |____Android
|___Release
|____Win32
|____Win64
|____Android
But after compile, the resulted structure was like below:
My_Delphi_Project_folder
Win32
Win64
Android
Bin
|___Debug
| |____Win32
| |____Win64
| |____Android
|___Release
|____Win32
|____Win64
|____Android
After investigating .dproj file I found the guilty. It was DCC_ExeOutput.
As I didn't find a way to configures it in Delphi, I asked for help here.
It has a long time that I don't work with Delphi, and I thought that could be a very simple thing that I have passed up. That's the cause of lack of information in my question.
See "Output Directory" in Project Options.
The important information here is the type of project. Your project is a package. As such the DCC_ExeOutput setting is not relevant. It has no impact on the build process. What matters for a package is the DCC_BplOutput setting. The IDE still appears to emit to the .dproj file a value for the DCC_ExeOutput setting, but this value is ignored, and can be removed from the .dproj file.
Package projects
Main source file begins with package.
The output location for the package is determined by the DCC_BplOutput node in the .dproj file.
In the IDE this setting corresponds to the Package output directory option in the project options dialog.
The IDE's new package dialog produces a .dproj file that contains a DCC_ExeOutput node. This node is ignored and can safely be removed from the .dproj file. There is no option in the IDE that corresponds to the DCC_ExeOutput node in a package .dproj file.
Executable and library projects
Main source file begins with program or library.
The output location for the project is determined by the DCC_ExeOutput node in the .dproj file.
In the IDE this setting corresponds to the Output directory option in the project options dialog.

DELPHI Compiler Path settings after INDY 10 upgrade

I already asked how to upgrade to the latest Indy TCP TP components version ( GET INDY COMPONENTS ) and Installed Indy 10 with DELPHI XE 2 now. For all the Indy projects I defined an outfolder in the project options section of DELPHI XE2, here I found later all the the .bpl files and all the -DCU#s files I need now in order to compile my application using the new INDY components to add this output folder as a library search path in these projects.
I found at my XE2 installation a path/folder with *.dcu files for x32, x64, release and debug mode (C:\Program Files (x86)\Embarcadero\RAD Studio\9.0\lib\win64\release).
Do I need now all the INDY *.dcu I have created also in these different flavours compiled, how to set the path for all project to use the new *.dcu from my folder ?
Should I copy all my dcu's to these many sub folders ??
You should not replace the pre-installed Indy files with the updated compiled files (in case you need the originals in the future, such as for DataSnap projects). Install the newer Indy into its own separate folder, then update the projects search paths to refer to that installation's output folder(s) instread of the pre-installed folder(s).
You should not overwrite the .dcu files that are part of the Delphi installation. What's more, I would not recommend that you do anything with the .dcu files that you used to build these .bpl files.
What you should do is to include the Indy source files, the .pas files, in your project. Personally I prefer to avoid using a search path to achieve that and instead simply add all the necessary .pas files to the project. But you may prefer to use the search path option.
But the main point is that since this project is supplied in source form it is best to compile the source yourself, as part of your project. That makes it much easier for you, whilst debugging, to step through the Indy code. There's no need to have separate DCU files for release and debug. It makes the build process simpler, only one thing to build. It makes it easier if your source code targets multiple Delphi compiler versions.

Where do I find the bpl file after I compile a package?

I want to create *.bpl file but I am failing to do so.
Specifically, I am trying to make JEDI plugins, but I have tried an empty pure Delphi package, too.
If I create a new package in Delphi XE3, I get an empty unit - if I "make" this project called "Package1.bpl", I get a .dcu file in "debug/win32/", but no .bpl file.
No error is reported by the compiler.
An empty JEDI plugin (bpl-style) only gives a .dcu, too, while an empty dll-style JEDI plugin gives a .cdu and a .dll file in "debug/win32/".
This is the first time I am trying to make a new package, so I am completely lost.
What am I missing?
Go to the Tools menu and navigate to Environment Options -> Delphi Options -> Library.
There you find the Package Output Directory and the DCP Output Directory. These directories are the default output directories for BPLs and DCPs, so the bpl will be created if your packages is compiled, but in a different directory from what you expect.
The JEDI plugins probably have their output directory configured otherwise in Project -> Options.
For those that don't want to travel into Delphi IDE/options etc, lately in Delphi XE it's something like this:
"C:\Users\Public\Documents\Embarcadero\Studio\17.0\Bpl;"
Your exact folder might be different based on 17.0
These folders also end up in the path environment variable of your system, bit dangerous and can lead to some mighty magic loading confusion ?!
"How's that BPL still loading after it was deleted from my local project folder ?" :)
Another solution is to add "." to your project settings without the "". Prevents you from having to modify your delphi environment options/settings, something you probably never want to do since JEDI and other projects may rely on these default settings to function properly. Only change it if you know what you are doing and how to correctly make JEDI and others work if it was changed, this may get tricky/hairy, probably requires search paths to be added.

Resources