0

I have written a project that is designed to be a single header include. Since I have written many smaller files that do specific things it would be easier to have a preprocessor only process the includes so that everything can be combined into one file with the other preprocessor statements NOT executed. Is this possible with g++?

I have used the command g++ file.h -E -P -o file.i but this preprocesses all of the preprocessor statements

K-D-G
  • 160
  • 1
  • 8
  • 1
    The preprocessor preprocesses. It sounds like you just want to concatenate all files into a single file. Can't you just use `cat` for that? – Nikos C. Apr 11 '19 at 12:38
  • 1
    Possible duplicate of [Merge C++ files into a single source file](https://stackoverflow.com/questions/5995773/merge-c-files-into-a-single-source-file) – Lanting Apr 11 '19 at 12:41
  • 2
    Given that some files may be included only if a macro is defined, this is logically impossible. In such cases the preprocessor needs to test/expand macros before deciding whether to `#include` a file. More generally, the preprocessor runs through sequentially from beginning to end - it doesn't do one phase of including files then another of expanding macros. It does whatever is needed on each line, based on what has come before, and then continues to the next – Peter Apr 11 '19 at 12:42
  • @Peter: That would make a perfect Answer. – Beta Apr 11 '19 at 13:39

0 Answers0