You may be looking for the unifdef utility.
Say I have two header files A.hpp and B.hpp, and A.hpp is included in the second file using the #include "A.hpp" instruction. Now, when distributing header files, I need another option, which includes one header file, A_B.hpp, which contains exactly the same code as the contents of A.hpp inserted above its #include statement.
Actually, you do not say that A.hpp and B.hpp (and details are important). They probably include some system headers (for example, <stdio.h> from the C standard library or <new> or <vector> headers from the C ++ standard library). Then distributing their pre-processed form (output g++ -C -E b.hpp ...) is practically useless, because this form then contains some system / compiler-specific declarations / definitions that are not portable to another compiler (in practice, <map> from GCC 5 is probably not compatible with <map> from GCC 6).
The whole point of standard libraries is that they normalize the name of the headers (and their public interfaces), such as <vector> or <stdio.h> , but not the details of their contents (and private implementations). And compilation options (e.g. -pthread or -std=gnu++11 or -O ...) can influence the pre-processed form (especially through common predefined macros ).
You can use the -H version of the preprocessor before g++ to find out what is included (or even play tricks with various -M ...).
You might want to distribute the source code pooling (for example, SQLite does ), but this requires some careful development effort.
You can use some external preprocessor, such as m4 or GPP .
(but it is project specific and much less simple than you think, precisely because of the role of standard headers in your projects)
source share