Phonon
Phonon

Reputation: 12727

How do I find out which header g++ includes?

I'm compiling an open-source project which fails saying that the sincos function is not declared. When I look in math.h, the declaration is there. I added a warning to the very top of math.h to see if it gets included (a warning would be printed if it does), and it actually never gets printed when I compile the code. Hence, I assume that it may get included from somewhere other than /usr/include/math.h.

The problem is that it's a giant codebase and is quite impenetrable as far as tracing include directories and such by hand.

Is there a way I can tell g++ to print full paths of all includes that it resolves?

Upvotes: 1

Views: 114

Answers (2)

Peter M
Peter M

Reputation: 1988

In addition to g++ -E -C, I find the -v argument useful for this situation. It will give you all of the default search paths/sysrooty stuff, as well as any default internal arguments passed to the sub-tools.

Additionally, this command will tell you if gcc is attempting to use a default include path that doesn't exist, which is a common issue in incorrectly configured gcc toolchains.

Upvotes: 0

teppic
teppic

Reputation: 8195

You can use the -E option to run the preprocessor only. This will produce the source code after preprocessing with all the header files, which is likely to be very long.

Instead you can generate a makefile to show the dependencies. If you use -E -M, you should see a list of all include files the file depends on.

Upvotes: 3

Related Questions