Why do I need to include the precompiled header in

2019-06-06 11:11发布

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?

2条回答
\"骚年 ilove
2楼-- · 2019-06-06 11:39

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.

查看更多
淡お忘
3楼-- · 2019-06-06 11:40

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!

查看更多
登录 后发表回答