ivan_pozdeev
ivan_pozdeev

Reputation: 36086

include processed prepocessor directives into `g++ -E' output

I'm having some preprocessing mishap while compiling a 3rd party library with g++.

I can see in -E output that a certain header wrapped with #ifndef SYMBOL is being bypassed. Apparently, that symbol has been defined somewhere else. But I cannot see where because processed directives are not present in the -E output.

Is there a way to include them (as comments, probably)?

Upvotes: 1

Views: 82

Answers (2)

ivan_pozdeev
ivan_pozdeev

Reputation: 36086

The closest thing I found is the -d<chars> family of options:

  • -dM dumps all the macros that are defined
  • -dD shows where they are defined (dumps #define directives)
  • -dU shows where they are used (in place of #if(n)def, it outputs #define or #undef depending on whether the macro was defined)

    Adding I to any of these also dumps #include directives.

The downside is only one of the three can be used at a time and they suppress normal output.

Another, less understandable downside is -dD and -dU do not include predefined macros.

Upvotes: 1

No, there is no standard way to get preprocessed directives as comments.

However, you could use g++ -C -E and the line numbers (output in lines starting with #) and the comments (which are then copied to the preprocessed form).

And you might also use the -H option (to get the included files)

Upvotes: 1

Related Questions