如何在项目中实现预编译的头文件 [英] How to implement precompiled headers into your project

查看:861
本文介绍了如何在项目中实现预编译的头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解预编译头文件的目的和推理。但是,实施它们时的规则是什么?从我的理解,它像这样:

I understand the purpose and reasoning behind precompiled headers. However, what are the rules when implementing them? From my understanding, it goes something like this:


  1. 将您的项目设置为使用YU指令使用预编译头。

  2. 创建您的stdafx.h文件并将其设置为您的预编译头。

  3. 将每个.h文件中的顶部include语句包含在内。

这样是否正确?应该排除包含在预编译头文件中的文件吗?目前,我按照我的直觉用下面的编译错误:

It this correct? Should you exclude the including it in the files that are included within your precompiled header? Currently, I get the following compilation error when following my intuition with this:


错误C2857:'#include'语句
指定在
中找不到/Ycstdafx.h
命令行选项源文件

error C2857: '#include' statement specified with the /Ycstdafx.h command-line option was not found in the source file

命令-line选项是这样:

The command-line options are as such:


/ Od / I
../External/PlatformSDK/Include/ I
../ I../External/atlmfc/Include
/ D_DEBUG/ D_UNICODE/ DUNICODE
/ 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
/ errorReport:prompt

/Od /I "../External/PlatformSDK/Include" /I ".." /I "../External/atlmfc/Include" /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 /errorReport:prompt


推荐答案

您的stdafx.cpp应包括stdafx.h并使用 / Ycstdafx.h

You stdafx.cpp should include stdafx.h and be built using /Yc"stdafx.h".

构建您的其他* .cpp应包括stdafx。 h并使用 / Yustdafx.h

Your other *.cpp should be include stdafx.h and be built using /Yu"stdafx.h".

请注意使用双引号字符编译器选项!

Note the double-quote characters used in the compiler options!

下面是stdafx.cpp创建预编译头文件的Visual Studio设置的屏幕截图:

Here's a screenshot of the Visual Studio settings for stdafx.cpp to create a precompiled header:

这里是相应的命令-line选项(只读,但反映在其他页面上指定的设置;注意IDE在编译器选项中在文件名周围插入双引号字符):

Here are the corresponding command-line options (which are read-only but reflect the settings specified on other pages; note that the IDE inserts double-quote characters around the filename, in the compiler option):

这是我的stdafx.cpp文件中的内容:

This is what's in my stdafx.cpp file:

// 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

这篇关于如何在项目中实现预编译的头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆