RAD Studio
ContentsIndex
PreviousUpNext
Using Include Files

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

The CodeGear C++ 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. In addition, if you use the statement: #include <vcl\vcl.h> and you set the Include option (-I) 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 (‑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 flies that include (#include) that file.
    3. The current directory
    4. The directories specified with the include (-I) option

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

  • Implicit libraries: The CodeGear C++ compiler searches for implicit libraries only in the specified library directories; 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: Where the compiler searches for explicit (user-specified) libraries depends in part on how you list the library file name. 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 (‑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 CodeGear C++ compiler searches only in the location you explicitly listed as part of the library path name and not in any specified library directories.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!