在 Visual C++ 中使用预编译头的最不显眼的方式是什么?
假设我有一个项目,其中包含文件 A.cpp、B.cpp、C.ppp 和匹配的头文件(仅此而已)。 C++ 文件包含系统头文件或其他模块的头文件。
我想使用命令行操作(例如,使用 Make)、使用“cl”和预编译头功能将它们编译为库。
我应该采取哪些步骤?什么是命令行开关?
Say I have a single project, with files A.cpp, B.cpp, C.ppp and matching header files (and that's it). The C++ files include system headers or headers from other modules.
I want to compile them to a library with command line actions (e.g., using Make), using 'cl', with the precompiled headers feature.
What are the steps I should do? What are the command line switches?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
预编译标头是通过创建包含要预编译的标头的 .cpp 来完成的。通常,stdafx.cpp 用于此目的。
还有其他方法,但我发现这是最简单的。
Precompiled Headers are done by creating a .cpp that includes the headers you want to be pre-compiled. Normally, stdafx.cpp is used for this purpose.
There are other ways, but I find this to be the simplest.
由于您使用的是 Visual Studio,我建议仅构建解决方案:
如果您确实需要执行每个单独的文件,您可以查看项目中每个文件的构建属性设置底部的命令行选项。它将显示您需要的所有开关。
对于 PCH,您需要做的就是确保首先编译创建 pch 的 cpp。
Since you are using visual studio I would recommend just building the solution:
If you really need to do each of the individual files you can look at the command line option at the bottom of the build properties settings for each file in your project. It will show all the switches that you need.
Regarding the PCH, all you need to do is make sure the cpp that is creating the pch is compiled first.