Using Include Files

From RAD Studio
Jump to: navigation, search

Go Up to Command-Line Utilities Index

In C++, include files always have the file extension .h.

Include File Search Algorithms

The BCC32.exe compiler searches for files included in your source code with the #include directive in the following ways:

  • If you specify a path and/or directory with your include statement, the compiler searches only the specified location.
    For example, if you have the following statement in your code:
    #include "c:\C++\include\vcl\vcl.h"
    the header file vcl.h must reside in the directory C:\C++\include\vcl.
    In addition, if you use the statement:
    #include <vcl\vcl.h>
    and you set the Include file search path (-I) option to specify the path C:\C++\include, the file vcl.h must reside in C:\C++\include\vcl, and not in C:\C++\include or C:\vcl.
  • If you put a
    #include <somefile>
    statement in your source code, the compiler searches for somefile only in the directories specified with the Include file search path (-I) option.
  • If you put a
    #include "somefile"
    statement in your code, the compiler will search for somefile in the following order:
    1. The same directory as the file containing the #include statement.
    2. The directories of files that include (#include) that file.
    3. The current directory.
    4. The directories specified with the Include file search path (-I) option.

Library File Search Algorithms

The library file search algorithms are similar to those for include files:

  • Implicit libraries: The C++ compiler searches for implicit libraries only in the specified library directories (Library path (-L) option). This is similar to the search algorithm for: #include "somefile". Implicit library files are the ones the compiler automatically links in and the start-up object file (C0x.OBJ).
  • Explicit libraries: How you list the library file determines in part where the compiler searches for explicit (user-specified) libraries. Explicit library files are ones you list on the command line or in a project file; these are file names with a .LIB extension.
    • If you list an explicit library file name with no drive or directory (such as MYLIB.LIB), the compiler first searches for that library in the current directory. If the first search is unsuccessful, the compiler looks in the directories specified with the Library path (-L) option. This is similar to the search algorithm for #include "somefile".
    • If you list a user-specified library with drive and/or directory information (like this: c:\mystuff\mylib1.lib), the C++ compiler searches only in the location you explicitly listed as part of the library path name and not in any specified library directories.

C++ Applications that Do Not Use VCL Forms Should Not Include <vcl.h>

That is, applications (such as console, database, or Web/SOAP applications) that do not use the GUI elements of the Visual Control Library (VCL) should not specify:

#include <vcl.h>

The <vcl.h> header includes all of the VCL Forms library, as well as the Delphi RTL.

If you want to use Delphi types (such as System.Set<>, System.Variant, or System.UnicodeString) in a non-visual C++ application, do either one of the following:

  • Specify:
    #include <System.hpp>
  • Include the appropriate unit that declares the types and API you want to use. For example:
    #include <Classes.hpp>
    #include <SysUtils.hpp>

In previous versions of C++Builder, the wizards, code examples, and application samples often used <vcl.h> as an easy way to access functionality exposed by the Delphi RTL package. However, C++Builder XE2 (and newer versions) must be able to distinguigh among UI frameworks (VCL vs FMX) and Target Platforms (Windows vs OSX).

Therefore, we recommend that you update all non-VCL code that includes vcl.h to instead include the appropriate header from the RTL, SOAP, Database, or other specific package. You can implement this by creating a precompiled header that includes the RTL headers required by your code. You might create, for example, <myheaders.h> that in turn includes the various RTL headers such as Classes.hpp, SysUtils.hpp, and so forth.

See Also