预编译头和 Visual Studio
有没有办法设置 Visual Studio 解决方案参数,以便它只创建预编译头而不构建整个解决方案。 具体来说,它是一个巨大的 C++ 解决方案,本身有许多项目。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
仅选择 pch 创建者源文件(通常是 stdafx.cpp),然后编译该文件(Ctrl-F7,或右键单击它并选择“编译”)
更多信息,因为它似乎不适合您:
在每个使用预编译头的项目中,都有一个用于创建 pch 文件的源文件,其余使用 pch 文件。该源文件通常只包含一行:
“Stdafx.h”是 Visual C++ 中默认的预编译头文件名,您也可以使用其他名称。如果您自行编译“StdAfx.cpp”,则会生成一个名为“Your_Project_Name.pch”的文件(同样,这只是默认值)。您应该在中间目录中看到它,该目录与所有 obj 文件所在的目录相同。这是预编译头。如果您像我说的那样,选择“编译”而不是“构建”,则不会编译其他文件,也不会发生链接。
如果仍然不能解决您的问题,那么我不知道您在问什么。
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:
"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.
这是一篇文章,描述了好处以及如何设置起来吧。
如果您有较大的项目,那么几次点击和额外的磁盘空间绝对值得。
文章说您需要将 stdafx.h 添加到所有源和标头中;这是不正确的。添加到源就足够了 - 确保它是第一行,因为它之前的所有内容都将被忽略。
本文没有提及它,但您将从不包含 stdafx.h 的源中收到错误。您可以选择解决此错误:添加它,或从预编译过程中排除源。
要排除源文件:
从现在开始,只需几秒钟即可享受您的新构建(第一个构建将需要更长的时间)。
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:
Enjoy your new builds in a few seconds from here on (the first build will take longer).
如果右键单击项目中除 stdafx.cpp 之外的任何 Cpp 文件并将“从构建中排除”设置为“是”,它将仅生成预编译头。
您可以通过命令行或创建仅包含 stdafx.cpp 的新项目来实现相同的结果
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