Search code examples
c++include

Is there a way to auto-include a file into all source files in C++/C#?


I've been periodically in the position to need to include a single file with my own definitions and other frequent code into every other source file.
From what I know, MSVS 2013 as well as other compilers allows easy inclusion of multiple files into one but haven't seen easy inclusion of one file into multiple ones.
Currently I have to manually include the frequent code file in dozens of files for which reason I consider myself ignorant.
There has to be a way to specify "global" files, visible from anywhere. And thinking about the fact that the compiler/linker sweeps through all cpp's in the project anyway...
EDIT: As per a comment below, how can "force include", as in -include argument for GCC, be achieved in MSVS?


Solution

  • I found exactly what I needed here:
    https://msdn.microsoft.com/en-us/library/8c5ztk84.aspx
    I tested it and commented out #include's of the Definitions.hpp, i.e. the frequently used code and it doesn't show any error.