A quick guide to using Precompiled Headers (Visual Studio)

Precompiled headers can be a very useful thing. Increase productivity by saving time otherwise would have spent on compiling.

This is a quick guide on how to setup precompiled headers in Visual Studio (specifically VS2012). I’m not going to explain what it is, or why you might want it. So let’s go.

I will assume that you currently have a project that does not have precompiled headers setup but you want it now, or later down the road.


When you create a new project in Visual Studio, and you select a template such as the “Win32 Console Application” template. The Win32 Application Wizard will open and attempt to guide you through the basic configurations of the project. A tickbox is provided for if you want Precompiled header. This is not the case when you create an empty project. The Wizard simply does not appear.

To setup Precompiled Header. First create two source files: “stdafx.h” and “stdafx.cpp” (For the tinkers. It actually doesn’t matter what you name them.) , and add them to your projects.


Now select all source files (your .cpp files) in the Solution Explorer, right click and hit Properties. The Property Page should pop up.


In the Property Pages, head to “Configuration Properties” – > “C/C++” -> “Precompiled Headers”. Change “Precompiled Header” to “Use (/Yu)”. Click “Apply” at the bottom right and click “OK” to close the page. Next, go back to Solution Explorer. Select and right click on the file “stdafx.cpp” (or whatever you named it), and click on “Properties” again. Navigate to “Configuration Properties” – > “C/C++” -> “Precompiled Headers” (again).


This time, change “Precompiled Header” to “Create (/Yc)”. Again, click “Apply” at the bottom right and click “OK” to close the page.

Lastly. Do your usual “#ifndef #define #endif” or “#pragma once” include guard inside the “stdafx.h” file, and include this file in EVERY single file inside your project. That’s right. Every single one of them. Now, rebuild your solution and it should be all good.

[code language=”cpp”]
#pragma once
#include "stdafx.h"
#include <iostream>
// etc …

Remember that “#include “stdafx.h” ” must appear before every #include in every file. Otherwise the preprocessor/compiler will happily ignore anything before it and throw you errors.

That’s all. Hope this little guide will help those that were lost and confused like me.  Here’s a couple links that will explain what Precompiled Header is to some extent. It’s best to do your own Google foo on this topic.




Bye for now.

Infinity Box Studios

Infinity Box Studio
The prototype Infinity Box Studios logo

With work already started on my first game project, I’ve came up with a name for my own “studio” and registered a new domain with new hosting. The game will be a remake of the old Stick Soldiers franchise, with new features coming later(more posts on this in the future). Stick Soldiers 2 was never completed, and Stick Soldiers 3 was also abandoned. I liked the game enough that I think I should try bringing it back.

The DDNS on my Synology NAS has been causing me a lot of grief lately so I’ve also moved my personal website along with my little brother Kevin’s little website onto the new domain. I will probably keep it around for site development and update testing.

There isn’t much content as for now, but stay tuned!

At last, links to the new and old sites:

Bye now.



My dedication for the next two or few years.

It was funny when I’ve finally decided that I wanted to become a programmer, a software developer. The builder of something that is the glue of all trades in this digital world. It all seemed so long a go.

Being a programmer, fundamentally meant one thing. To speak one or multiple languages that are at the end of the day, just a bucket load of 1’s and 0’s. Not only that, but to express ideas freely and creatively using those languages. To cultivate innovations and revolutions. Kind of like a poet and his poems, except with programming languages.

I wasn’t sure which one to start with. Where to take my first step and dip my foot in without drowning and be forced to retreat like a coward. With the massive variety programming languages out there, I did not want to learn or know them all. It was clear that the mastery of one is better than minimal knowledge of a couple. I also desired the highest performance and the best flexibility without losing fine grain control and power. With the general trend shifting favour to scripting, dynamic languages and producing web applications instead of native ones. It seemed like lower level programming languages will soon become what some might call a forgotten art to the majority of the “developer” community. Especially with the ever decreasing difficulty in application development with the newer high level programming languages.

At the end, I chose C++. I’ve decided to tame this beast and master it with all I can.

Was this the right decision? Is this a good investment?
Only time will tell.