Hey i’ve been following learncpp.com tuts for the last couple days, they say to comment out “#include “stdafx.h” from .cpp files for Code::Blocks.
Is that a must, to remove the include line? What happens if you had hundreds of files and changed from Visual Studio on Win7 to Code::Blocks on Linux or hand it off to someone else with a mac?
stdafx.his the idiomatic name used for precompiled headers in the Visual Studio ecosystem. In a nutshell, it’s a regular header, but the contents of this file will be compiled once and reused for all cpp files in the project.That is useful since in most projects, a large number of headers (standard library, system header, shared project-wide definitions) are used by virtually all translation units (cpps), so using PCH is a huge performance benefit during compilation
(Actually, PCH is a hack to workaround C++’ inefficient compilation and linkage model and it’s a shame that we need to maintain it by hand … oups, blasphemy.)
But this also means that – as long as the contents of your
stdafx.hare gcc-compatible – compilation with CodeBlocks should still work, but without the immediate performance benefit.The
stdafx.hgenerated by VS’ app wizards doesn’t work out of the box on other platforms – it typically includesWindows.h. So to make it work, guard the Windows-specific definitions with appropriate#ifdef/#endifpairs and vice versa for Linux or Mac-specific stuff.