Using Include Files

From RAD Studio
Jump to: navigation, search

Go Up to BCC32


In C++, header files always have the file extension .h or .hpp.

Include File Search Algorithms

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

  • If you specify a path 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 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 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 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 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 the ones that 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 option. This is similar to the search algorithm for #include "somefile".
    • If you list a user-specified library with drive or directory information (such as 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.

See Also