I'm having trouble with someone else's code, what seems to be header files included out of order. (E.g., I'm getting redefinition errors, some of which are even in the same file!) It would be useful to see the #include tree the C++Builder compiler is using, similar to Visual Studio's -showIncludes flag. Is there any such functionality; if so, how do I access it? I am specifically using C++Builder 2007.
2 Answers
This usually happens if you including multiple times files which contains global constants, variables and sometimes even #defines
. This is very common for MDI apps where the master Form
contains include of the child Form
s and some of them use the same libs ...
The include hierarchy would not help for this unless you are planning to edit all source files #include
order which can lead to problems later on (especially compatibility)...
To remedy this you should encapsulate all such files with
#ifndef _file_name_h
#define _file_name_h
// here your source and includes
#endif
statements. Like in this example:
That will prevent multiple definitions and compilations on pre-compiler level as the source will be processed only the first time (while #define _file_name_h
is still not defined).
Sadly, there are no Borland C Compiler options for displaying the hierarchy of #include
d files. See Embarcadero's BCC32 CLI docs.
However, an alternative (granted, not as clean) is to use the Borland C Compiler Preprocessor, e.g.
CPP32 -Sr source.cpp # outputs source.i with comments and indentation retained

- 2,793
- 7
- 34
- 62