0

I'm working with Visual Studio 2010 and with the common pattern of having a single class per header and source file (of the same name as the class).

Now I would like to compose a single header file containing all / some of the headers in an order based on the internal dependencies, i.e., the definition of class B before that of class A, if A depends on B (i.e., if "A.h" includes "B.h").

Is there any build-in tool for this? How is this commonly done?

Niko
  • 26,516
  • 9
  • 93
  • 110
  • You mean you want to create this header file automatically? I assume you know how to create a .h file and type a bunch of `#includes` into it, right? – Nate Hekman Apr 17 '13 at 20:15
  • @NateHekman Right. Basically, I'd like to be able to use the static library in other projects with only this single header file instead of the whole bunch that I'm actually working with when developing the library itself. I've seen this numerous times, especially in hardware interfaces etc. – Niko Apr 17 '13 at 20:19
  • If A depends on B, and and "A.h" has `#include "B.h"` at the top, then why does it matter what order "A.h" and "B.h" get included in, since the dependencies are taken care of within each header? – JBentley Apr 17 '13 at 20:22
  • @JBentley I want to create a header "X.h" which combines the content of "A.h" and "B.h" (not by simply including them but by copying the whole content of the files into "X.h"!). This would somehow require to remove `#include "B.h"` from "A.h" and instead place the definition of B before that of A. – Niko Apr 17 '13 at 20:30
  • 1
    @Niko Ah, I see. This still raises the question of why - would it not be better to provide the original headers, plus a single header comprised of `#include`s; that way your user is not forced to include your entire library if he only wants one part of it, whilst still giving the option of a convenient single header? I'm not aware of a tool to automatically do what you're asking, but perhaps someone else will offer up a solution. – JBentley Apr 17 '13 at 20:37
  • @Niko Have a look at [this question](http://stackoverflow.com/questions/277258/c-c-source-file-after-preprocessing), perhaps that would do what you need? I.e. just create a single header which `#include`s all of yours (in any random order), let the preprocessor take care of it, then use the output. This could have implications for other preprocessor directives though, so maybe not an ideal solution (since really it's only the `#include`s that you want preprocessed at that point). – JBentley Apr 17 '13 at 20:42

0 Answers0