开发者

Precompiled header and Visual Studio

Is there a way to set Visual Studio solution parameters so it just create precompiled headers without building whole solution. Specifically, it is a huge c++ solution with many projects in itself开发者_开发技巧.

Thank you.


Only select the pch creator source file (usually stdafx.cpp), and compile that (Ctrl-F7, or right-click it and select 'Compile')

More info since it doesn't seem to be working for you:

In every project that uses a precompiled header, there is one source file that is used to create the pch file, and the rest only use the pch file. This source file usually only consists of one line:

#include "StdAfx.h"

"Stdafx.h" is the default precompiled header file name in Visual C++, it could be something else for you. If you compile "StdAfx.cpp" by itself, that generates a file with the name "Your_Project_Name.pch" (again, that's only the default). You should see it in the intermediate directory, the same one where all the obj files are. This is the precompiled header. If you did like I said, and selected 'Compile' and not 'Build', then no other files will be compiled, and no linking will take place.

If that still does not solve your problem, then I have no idea what you are asking.


Here's an article describing the benefits and how to set it up. If you have larger projects, it is definitely worth the few clicks and the extra disk space.

The article says you need to add stdafx.h to all sources and headers; it's not correct. It's sufficient to add to sources - make sure it's the first line though as everything before it will be ignored.

The article does not mention it, but you'll be getting errors from sources that do not include the stdafx.h. You have a choice to resolve this error: you either add it, or exclude the source(s) from the precompilation process. To exclude source files:

  • select source file(s) in the solution explorer; yes you can select more at once,
  • right click on the highlighted source file,
  • click properties from the pop-up menu,
  • select 'All configurations' from the combo-box on top,
  • under C-C++ configuration click 'Precompiled headers',
  • on the right-hand side select 'Not using precompiled headers',
  • click apply,
  • click ok.

Enjoy your new builds in a few seconds from here on (the first build will take longer).


If you right-click any Cpp files except stdafx.cpp from your project and set Excluded from build to Yes, it will only generate the precompiled header.

You can achieve the same result through the command line or if you create new project containing only your stdafx.cpp

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜