How to implement precompiled headers into your project

后端 未结 4 1420
鱼传尺愫
鱼传尺愫 2021-01-30 07:19

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:

4条回答
  •  野性不改
    2021-01-30 08:09

    You stdafx.cpp should include stdafx.h and be built using /Yc"stdafx.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!

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

    create precompiled header

    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):

    options

    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
    

提交回复
热议问题