I've got a file such as this:#ifndef STDINCLUDE#define STDINCLUDE#include <memory>#include <stdexcept>#endifI want this file to be included in every header file, because I use stuff from those headers so much. Is it preferable to include this via compiler options (-I stdinclude.hpp), or should I physically include them in each header? (#include <stdinclude>). Note that I am attempting to be cross-platform-minded. I use cmake to serve atleast Unix and Windows.
Should a standard include header be specified in each file or as a compiler parameter?
c++;compiler;project structure
For many compilers, including gcc, the -I option specifies a directory to search for include files, not an individual file.  I don't know of an option to include a single file.  For one thing, such an object would not specify where in the source to place the #include directive.Even if there were such an option, I would not recommend using it.  The choice of which headers to include is information that should be in the source file.  If you were to specify it on the command line, you'd be decoupling that information from the source file (presumably it would be in a Makefile or something similar), which would make the source code more difficult to understand and maintain.  And anyone trying to port your software to a different build system would have to port that option separately.Presumably most of your source files include headers other than stdinclude.hpp.  Including that one file via a compiler option, and everything else via explicit #include directives, is arbitrary and potentially confusing.By having an explicit#include <stdheader.hpp>or, since it's part of your project:#include stdheader.hppyou let the reader know that your code uses something defined in that header.If that's all there is to your stdheader.hpp file, you might even consider dropping it and having each source file use#include <memory>#include <stdexcept>directly.  That way, your readers will know exactly what's being #included, and won't have to know or care what's in stdheader.hpp.  That's a pretty good benefit for one extra line per file.  If stdheader.h becomes more elaborate, using it might make more sense.