stdafx.h is the idiomatic name used for precompiled headers in the Visual Studio ecosystem. In short, this is a common header, but the contents of this file will be compiled once and reused for all cpp files in the project.
This is useful because in most projects a large number of headers (standard library, system title, common definitions for the whole project) are used by almost all translation units (cpps), so using PCH is a huge performance benefit when compiling
(Actually, PCH is to crack the inefficient C ++ compilation and binding model, and it's a shame that we need to maintain manually ... oups, blasphemy.)
But it also means that - as long as the contents of your stdafx.h are gcc compatible - compiling with CodeBlocks should work, but without the immediate performance benefit.
stdafx.h , created by VS application wizards, does not work out of the box on other platforms - it usually includes Windows.h . Therefore, to make it work, protect certain Windows definitions with the appropriate #ifdef/#endif pairs and vice versa for Linux or Mac-specific things.
Alexander Gessler
source share