What is the difference between “Create Precompiled Header” (/Yc) and “Use Precompiled Header” (/Yu) in Visual Studio?

冷暖自知 提交于 2019-12-18 12:54:38

问题


I read the documentation in MSDN, but in the end I didn't get a clear idea what is the practical difference between them, exactly. Both seem to require stdafx.h to be added at the top of every *.cpp file.

I'm using VS2008.

Can anyone help clear things up?


回答1:


Well, I think that you must first understand the purpose of precompiled headers. In large projects, it can take ages to process all the headers required by a single client extension for example, so some people prefer to distribute the .pch files along with their libraries. In order to generate the .pch files, you use the /Yc compiler flag and the person who wants to consume your library will set the /Yu flag. See here and here for details.




回答2:


Short summary of how to use PCH files in Visual Studio:

  • All cpp files in the project have to include stdafx.h (you can change this to something else if you wish)
  • Select project in Solution Explorer and in Properties -> C++ -> Precompiled Headers set 'Create/Use precompiled headers' to 'Use'. Hit Apply
  • While the Property Pages are still shown select stdafx.cpp in solution explorer and set the value to 'Create'


来源:https://stackoverflow.com/questions/11722944/what-is-the-difference-between-create-precompiled-header-yc-and-use-precom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!