unj2
unj2

Reputation: 53491

Why do I need to include the precompiled header in all the files in C++?

If I don't include the stdafx even in an empty .cpp, I get this error

fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?

Why do I need to include it even in dummy files?

Upvotes: 2

Views: 2121

Answers (2)

user541686
user541686

Reputation: 210485

If you use them, then you must include them. But you can turn them off in the project properties.

However, the recommended way to use them is to "Force Include" the PCH from the command line, so that the file itself doesn't contain the PCH. That way the source file can be compatible with other systems.

Upvotes: 5

Rook
Rook

Reputation: 6145

You can disable precompiled headers per translation unit (in the properties for a given CPP file). You can probably do it per project too, if you're willing to explore the configuration GUI. Not all project types specify a PCH either; its just the standard Microsoft Way.

I've never encountered them outside of Microsoft land, so "in C++" is a little over general!

Upvotes: 6

Related Questions