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.hpp"
you 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 #include
d, 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.