3

Scenario

From time to time I get compiler errors in system headers. Currently for example:

c:\Programme\Microsoft Visual Studio 9.0\VC\ce\include\streambuf(55) : error C2143: syntax error : missing ')' before 'string'

As always, this is a false error message and of course there is a problem in my code. However, the compiler is not capable to tell me where it hurts. So I was looking for the usual suspects, e.g. "using namespace XXX" in some header files or something like that.

My problem is, I do not even know via which way the file streambuf was included into my code. At least I do not include it directly.

Concrete question

Is there a way to get some kind of "inclusion tree"? Something like

myClass.cpp
  + myClass.h
    + ios
      ...
      + streambuf

so I would be able to determine the error location a bit better.

JBentley
  • 6,099
  • 5
  • 37
  • 72
Seven
  • 4,353
  • 2
  • 27
  • 30
  • @JBentley: Thank you. This *is* a duplicate and that compiler switch was exactly what I was looking for. Unfortunately I couldn't find that question before posting... – Seven Apr 11 '13 at 14:59

1 Answers1

2

I typically use

cl /c /P /d1PP file.cpp

This creates a file.i. This is the preprocessed file - it contains all the headers as processed i.e. if a particular part of the header is under ifdef something & you haven't defined that something, it will not contain that block. The /d1PP (undocumented, I think) also show you where the macros are actually defined. You also will see who included streambuf in your code and at what point.

I then compile file.i as

cl /c /Tp file.i (or cl /c /Tc file.i - if it's C and not C++)

For visualisation, try this - http://www.codeproject.com/Articles/3478/Include-File-Hierarchy-Viewer

user93353
  • 13,733
  • 8
  • 60
  • 122
  • Thank you. I actually was looking for a visualisation of inclusion tree. Howeve, your method would be the second step when analysing the resulting source. – Seven Apr 11 '13 at 15:01