What is the proper way to use stdafx.h
, in terms of separating dependencies?
If I put everything in there, then my compiles are blazing fast, and all I need to say in any file is
#include "stdafx.h"
with the caveats that:
#include
s from C++ ones (e.g. cstring
versus string.h
) without a great deal of pain. (Speaking of which, does this even matter?)If I put nothing in there, I can organize everything well -- but then my compiles slow down dramatically.
If I put everything in there and also include every header in my individual files, then I get the best of both worlds, with the caveat that now I have to keep track of synchronization issues.
Is there a well-known/well-accepted solution to this problem?
Precompiled Header stdafx. h is basically used in Microsoft Visual Studio to let the compiler know the files that are once compiled and no need to compile it from scratch. The compiler would always compile this header files from scratch.
The file stdafx. h is usually used as a precompiled header file. Precompiled headers help to speed up compilation when a group of files in a project do not change.
h (named stdafx. h before Visual Studio 2017) is a file generated by the Microsoft Visual Studio IDE wizard, that describes both standard system and project specific include files that are used frequently but hardly ever change. The afx in stdafx. h stands for application framework extensions.
You shouldn't put your own header files in stdafx.h
since your code is likely to change and will cause your whole program to recompile.
I usually put standard headers and other libraries in there, such as all boost includes.
When using precompiled headers, you should make sure your project compiles cleanly even without PCH present (so treat it as optimisation, not a replacement for includes in every TU). Aside from that, don't put absolutely everything in there (and more importantly, don't ever put headers from your own project — PCH should contain only those that don't change or change very rarely — system libraries, external dependencies), but rather try to keep most used/biggest things precompiled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With