我了解预编译头背后的目的和推理。然而,实施时有哪些规则呢?根据我的理解,事情是这样的:
- 将您的项目设置为使用带有 YU 指令的预编译头。
- 创建 stdafx.h 文件并将其设置为预编译头。
- 将此作为每个 .h 文件中的顶部包含语句。
这是正确的吗?您是否应该将其排除在预编译头中包含的文件中?目前,当我遵循我的直觉时,出现以下编译错误:
错误 C2857:“#include”语句
使用 /Ycstdafx.h 指定
未找到命令行选项
源文件
命令行选项如下:
/Od /I
“../外部/PlatformSDK/包含”/I
“..”/I“../外部/atlmfc/包含”
/D“_DEBUG”/D“_UNICODE”/D“UNICODE”
/Gm /EHsc /RTC1 /MDd /Yc"stdafx.h"
/Fp"....\Output\LudoCore\Debug\LudoCore.pch"
/Fo"....\Output\LudoCore\Debug\"
/Fd"....\Output\LudoCore\Debug\vc80.pdb"
/W4 /WX /nologo /c /ZI /TP /wd4201
/错误报告:提示
您的 stdafx.cpp 应该包含 stdafx.h 并使用构建/Yc"stdafx.h"
.
您的其他 *.cpp 应包含 stdafx.h 并使用构建/Yu"stdafx.h"
.
请注意编译器选项中使用的双引号字符!
以下是用于 stdafx.cpp 创建预编译头的 Visual Studio 设置的屏幕截图:
以下是相应的命令行选项(它们是只读的,但反映了其他页面上指定的设置;请注意,IDE 在编译器选项中的文件名周围插入双引号字符):
这是我的 stdafx.cpp 文件中的内容:
// stdafx.cpp : source file that includes just the standard includes
// CallWinsock.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)