Question

I have a quite huge project.

And each of my .h file needs to include one specific file, errorHandler.h. But I don't want to do it by putting:

#include "errorHanlder.h"

at the top of each of them.

Moreover, in future I will have few implementations of errorHandler, so I would like to be able to change (fast) errorHandler.h to winErrorHandler.h, winErrorHandler2.h, unixErrorHandler.h or something like that.

Is there a possibility to include that file automatically using the Visual C++ 2012?

I mean something like automatic defines:

Project->Configuration Preporties->C/C++->Preprocessor->PreprocessorDefinitions When I write there e.g. myDef it's the same result as putting #define myDef in each file of project.

So in the same way, I would like to put somehow #include "errorHandler.h" in each file of project.

Was it helpful?

Solution

Is there a possibility to include that file automatically using the Visual C++ 2012?

You can use /FI to force an include of a file that's not included in the project's source files. I use it when porting libraries to Windows RT and Windows Phone. For example:

/FI SDKDDKVer.h /FI winapifamily.h

is effectively:

#include <SDKDDKVer.h>
#include <winapifamily.h>

Below is a patch I have for OpenSSL that forces some Windows Phone and Windows RT includes.

There's a property page for the option. You can find it at Project->Configuration Preporties->C/C++->Advanced->Force Include File (thanks PolGraphic and Retired Ninja).

The list of options for cl.exe is available at Compiler Options Listed Alphabetically. /I will allow you to specify a header path, like GCC's -I.


enter image description here

OTHER TIPS

If you are using the precompiled header feature then putting the common #include into stdafx.h will accomplish the same thing as putting it into every h file in the entire project. stdafx.h is processed before any other header.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top