2

What exactly is the -i option of the Delphi dcc command-line compilers (dcc32.exe, dcc64.exe, dcclinux64.exe and others)? As opposed to -u? Help just states this briefly (and Embarcadero documentation does not seem to expand upon the subject):

    -I<paths> = Include directories
    -U<paths> = Unit directories

For a while, I thought that -u is for including source code and -i for including precompiled .dcu files, but that does not seem to be the case. I also see cases where -i imports source code and -u imports .dcu files, and also that seems to work just fine. Another thought is that -u is meant to be the counterpart of the project's Search path in the Delphi IDE, and -i the counterpart of the Delphi IDE's global Library path, but that does not seem conclusive, either.

When should I use one or the other, -i or -u?

Matthias B
  • 404
  • 4
  • 11
  • 1
    `-I` option is used for `$INCLUDE` directive http://docwiki.embarcadero.com/RADStudio/Sydney/en/Include_file_(Delphi) – zed Mar 21 '21 at 08:56
  • I think not, because the -i option to dcc32 takes a list of paths, and not a file name, as argument. So it has to be something else, I believe. – Matthias B Mar 21 '21 at 09:12
  • 1
    It is, the documentation is very clear about this! – Delphi Coder Mar 21 '21 at 09:17
  • Could you please point to that documentation? I have searched thoroughly and not found any piece of documentation on it, except for the single line "-I = Include directories" that dcc32 -h outputs. – Matthias B Mar 21 '21 at 09:27
  • I'm sorry - the pointer given by @zed already does include it: "If the filename does not specify a directory path, then, in addition to searching for the file in the same directory as the current module, Delphi searches in the directories specified in the Search path input box on the Delphi Compiler page of the Project > Options dialog box (or in the directories specified in a -I option on the command line compiler)." So, indeed, it seems that this is the (sole?) purpose of the -i option to dcc32. Thank you! – Matthias B Mar 21 '21 at 09:29
  • 1
    -i and -u answer 2 different questions, where to look for include files named in Delphi source and where to look for Delphi unit files (.Pas and .Dcu). – MartynA Mar 21 '21 at 09:45
  • 1
    When you are unsure about a DCC command line, you may have a look at which command line the IDE uses. – fpiette Mar 21 '21 at 10:00
  • "-I = Include-file directories" would have been a more helpful wording in the help text that dcc32 -h outputs. Anyway, now I see what it is. Thank you all! – Matthias B Mar 21 '21 at 10:27

1 Answers1

4

The Remarks section of this page http://docwiki.embarcadero.com/RADStudio/Sydney/en/Include_file_(Delphi) begins

The $I parameter directive instructs the compiler to include the named file in the compilation. In effect, the file is inserted in the compiled text right after the {$I filename} directive.

The default extension for filename is .pas. A filename specified with no file extension always gets the .pas extension. If the filename does not specify a directory path, then, in addition to searching for the file in the same directory as the current module, Delphi searches in the directories specified in the Search path input box on the Delphi Compiler page of the Project > Options dialog box (or in the directories specified in a -I option on the command line compiler). ..."

The important thing to understand is that this is not talking about searching for source files in general, but rather for single files named in a source file by an

{$inc }

or

{$include }

directive in a source file. For example

unit SomeUnit;

{$inc SomeIncludeFile}

interface

[...]

Files named inside an {$inc} or {$include} directive are known as "include files" - hence the title topic of the quoted page. Subject to the restriction noted in the final paragraph of the Remarks, the directive can appear pretty much anywhere in a source file and, during compilation, the compiler substitutes the contents of the named file for the directive (including the filename). The support for include files in Turbo Pascal pre-dates its support for units and was primarily to ensure that two or more source files could behave as if they contained identical text, for example shared code or definitions.

The -i setting tells the compiler one or more folders in which to look for files such as SomeIncludeFile which are named by include directives the compiler encounters while compiling the source files in a project.

The -u setting tells the compiler where to look for unit files (e.g. .Pas and .Dcu ones) during a compilation.

MartynA
  • 30,454
  • 4
  • 32
  • 73
  • This is a good clarification - thank you! If you include in your answer (maybe first) also the basic fact that -i specifies directories to look in for include files (the actual, simple answer to the question, as given by @zed in the very first comment) and maybe the whole quote from Embarcadero's documentation, and then after that your current extra clarification about the difference between .inc files vs .pas and .dcu, then it will be a perfect answer and I will mark it as accepted rightaway. – Matthias B Mar 21 '21 at 11:19