Using Include Files
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 filevcl.h
must reside in the directoryC:\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 pathC:\C++\include
, the filevcl.h
must reside inC:\C++\include\vcl
, and not inC:\C++\include
orC:\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:- The same directory as the file containing the
#include
statement. - The directories of files that include (
#include
) that file. - The current directory.
- The directories specified with the Include file search path option.
- The same directory as the file containing the
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.
- If you list an explicit library file name with no drive or directory (such as