Search code examples
c++includeheader-files

Combining C++ header files


Is there an automated way to take a large amount of C++ header files and combine them in a single one?

This operation must, of course, concatenate the files in the right order so that no types, etc. are defined before they are used in upcoming classes and functions.

Basically, I'm looking for something that allows me to distribute my library in two files (libfoo.h, libfoo.a), instead of the current bunch of include files + the binary library.


Solution

  • As your comment says:

    .. I want to make it easier for library users, so they can just do one single #include and have it all.

    Then you could just spend some time, including all your headers in a "wrapper" header, in the right order. 50 headers are not that much. Just do something like:

    // libfoo.h
    #include "header1.h"
    #include "header2.h"
    // ..
    #include "headerN.h"
    

    This will not take that much time, if you do this manually.

    Also, adding new headers later - a matter of seconds, to add them in this "wrapper header".

    In my opinion, this is the most simple, clean and working solution.