I am working on a project that has a vendor-provided API. I’ve made a class that uses that API in my project and I’ve included the vendors header file in my stdafx.h file. Things would not compile.
I then put the #include directly into my class’ header file and now things compile (And yes, my class includes stdafx.h so that isn’t the reason.
Do any of you have any guesses as to why it wouldn’t compile the first time around? This isn’t a project-stopper by far but I’d prefer if I could keep all vendor API files in stdafx.h where they belong.
EDIT: Problem solved, I’d created a cyclic dependency by forgetting to #ifndef a header file and then including them in the wrong order. I feel like an idiot.
stdafx.his mainly used in the VS generated projects as the ‘container’ of headers to be precompiled.When you added a new
#includetostdafx.hit didn’t get included because your project is probably configured to use precompiled headers, and when you add something tostdafx.hyou need to regenerate the .pch file that contains the precompiled information.One way to do that is to have a .cpp file in your project that does nothing but
#include "stdafx.h". Maybe call it `precompile.cpp”. Then go to the project settings for that one .cpp file and change the following setting (for all configurations):and select
"Create /Yc".That will set up the build so that when
precompile.cppneeds to be built (because thestdafx.hheader it includes has changed), it’ll rebuild the .pch file that everything else uses.