Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell where a header file is included from?

Tags:

c++

c

include

gcc

g++

People also ask

How do you check if a header file is included?

To check if an header file has been included or not in a C or C++ code, we need to check if the macro defined in the header file is being defined in the client code. Standard header files like math. h have their own unique macro (like _MATH_H ) which we need to check. Consider this example of checking if math.

Where header files are stored?

The standard library header files are already in /usr/include , as you saw.

Where all header files are stored in C?

The angle brackets (<>) cause the preprocessor to search for the header file in the standard place for header files on your system, usually the /usr/include directory.

Which header file includes?

A header file is a file containing C declarations and macro definitions (see Macros) to be shared between several source files. You request the use of a header file in your program by including it, with the C preprocessing directive ' #include '. Header files serve two purposes.


g++ -H ...

will also print the full path of include files in a format which shows which header includes which


This will give make dependencies which list absolute paths of include files:

gcc  -M showtime.c

If you don't want the system includes (i.e. #include <something.h>) then use:

gcc  -MM showtime.c

Sure use

g++ -E -dI  ... (whatever the original command arguments were)

If you use -MM or one of the related options (-M, etc), you get just the list of headers that are included without having all the other preprocessor output (which you seem to get with the suggested g++ -E -dI solution).


If your build process is very complicated...

constexpr static auto iWillBreak = 
#include "where/the/heck/is/this/file.h"

This will (almost certainly) cause a compilation error near the top of the file in question. That should show you a compiler error with the path the compiler sees.

Obviously this is worse than the other answers, but sometimes this kind of hack is useful.