<small id='lhbGx'></small><noframes id='lhbGx'>

  • <tfoot id='lhbGx'></tfoot>
      <bdo id='lhbGx'></bdo><ul id='lhbGx'></ul>

      <legend id='lhbGx'><style id='lhbGx'><dir id='lhbGx'><q id='lhbGx'></q></dir></style></legend>
      1. <i id='lhbGx'><tr id='lhbGx'><dt id='lhbGx'><q id='lhbGx'><span id='lhbGx'><b id='lhbGx'><form id='lhbGx'><ins id='lhbGx'></ins><ul id='lhbGx'></ul><sub id='lhbGx'></sub></form><legend id='lhbGx'></legend><bdo id='lhbGx'><pre id='lhbGx'><center id='lhbGx'></center></pre></bdo></b><th id='lhbGx'></th></span></q></dt></tr></i><div id='lhbGx'><tfoot id='lhbGx'></tfoot><dl id='lhbGx'><fieldset id='lhbGx'></fieldset></dl></div>
      2. 在 Visual Studio 中的项目之间共享预编译头文件

        Sharing precompiled headers between projects in Visual Studio(在 Visual Studio 中的项目之间共享预编译头文件)
        <tfoot id='fT7gu'></tfoot>
      3. <i id='fT7gu'><tr id='fT7gu'><dt id='fT7gu'><q id='fT7gu'><span id='fT7gu'><b id='fT7gu'><form id='fT7gu'><ins id='fT7gu'></ins><ul id='fT7gu'></ul><sub id='fT7gu'></sub></form><legend id='fT7gu'></legend><bdo id='fT7gu'><pre id='fT7gu'><center id='fT7gu'></center></pre></bdo></b><th id='fT7gu'></th></span></q></dt></tr></i><div id='fT7gu'><tfoot id='fT7gu'></tfoot><dl id='fT7gu'><fieldset id='fT7gu'></fieldset></dl></div>
        • <small id='fT7gu'></small><noframes id='fT7gu'>

              <tbody id='fT7gu'></tbody>

            <legend id='fT7gu'><style id='fT7gu'><dir id='fT7gu'><q id='fT7gu'></q></dir></style></legend>

                • <bdo id='fT7gu'></bdo><ul id='fT7gu'></ul>
                • 本文介绍了在 Visual Studio 中的项目之间共享预编译头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个包含许多 Visual C++ 项目的解决方案,所有项目都使用 PCH,但有些项目针对特定项目的需要打开了特定的编译器开关.

                  I have a solution with many Visual C++ projects, all using PCH, but some have particular compiler switches turned on for project-specific needs.

                  这些项目中的大多数在各自的 stdafx.h(STL、boost 等)中共享同一组头文件.我想知道是否可以在项目之间共享 PCH,这样我就不必为每个项目编译每个 PCH,我可以拥有一个解决方案中的大多数项目都可以使用的通用 PCH.

                  Most of these projects share the same set of headers in their respective stdafx.h (STL, boost, etc). I'm wondering if it's possible to share PCH between projects, so that instead of compiling every PCH per-project I could maybe have one common PCH that most projects in the solution could just use.

                  似乎可以在项目设置中将 PCH 的位置指定为共享位置,所以我有预感这可以工作.我还假设所有使用共享 PCH 的项目中的所有源文件都必须具有相同的编译器设置,否则编译器会抱怨 PCH 和正在编译的源文件之间的不一致.

                  It seems possible to specify the location of the PCH as a shared location in the project settings, so I have a hunch this could work. I'm also assuming that all source files in all projects that use a shared PCH would have to have the same compiler settings, or else the compiler would complain about inconsistencies between the PCH and the source file being compiled.

                  有人试过吗?有用吗?

                  一个相关的问题:这样的分片 PCH 是否应该过于包容,还是会影响整体构建时间?例如,一个共享的 PCH 可能包含许多广泛使用的 STL 标头,但某些项目可能只需要 .使用共享 PCH 节省的时间是否必须在构建过程中的稍后时间得到回报,因为优化器必须丢弃 PCH 拖入项目中的所有未使用的东西?

                  A related question: should such a shard PCH be overly inclusive, or would that hurt overall build time? For example, a shared PCH could include many STL headers that are widely used, but some projecst might only need <string> and <vector>. Would the time saved by using a shared PCH have to be paid back at a later point in the build process when the optimizer would have to discard all the unused stuff dragged into the project by the PCH?

                  推荐答案

                  是的,我可以向您保证,节省的时间非常重要.编译 PCH 时,必须从创建 PCH 文件的项目中复制 .pdb.idb 文件.就我而言,我有一个简单的两个文件项目,用于创建 PCH 文件.标题将是您的 PCH 标题,并且源将被告知在项目设置下创建 PCH - 这类似于您在任何项目中通常会做的事情.正如您所提到的,您必须为每个配置设置相同的编译设置,否则会出现差异并且编译器会抱怨.

                  Yes it is possible and I can assure you, the time savings are significant. When you compile your PCH, you have to copy the .pdb and .idb files from the project that is creating the PCH file. In my case, I have a simple two file project that is creating a PCH file. The header will be your PCH header and the source will be told to create the PCH under project settings - this is similar to what you would do normally in any project. As you mentioned, you have to have the same compile settings for each configuration otherwise a discrepancy will arise and the compiler will complain.

                  每次重建或每次重新编译 PCH 时都复制上述文件会很痛苦,因此我们将其自动化.要自动复制,请执行预构建事件,将上述文件复制到适当的目录.例如,如果您正在编译 PCH 的 DebugRelease 构建,请将 PCH 项目的 Debug 中的文件复制到依赖项目的调试.所以复制命令看起来像这样

                  Copying the above mentioned files every time there is a rebuild or every time the PCH is recompiled is going to be a pain, so we will automate it. To automate copying, perform a pre-build event where the above mentioned files are copied over to the appropriate directory. For example, if you are compiling Debug and Release builds of your PCH, copy the files from Debug of your PCH project over to your dependent project's Debug. So a copy command would look like this

                  复制 PchPathDebug*.pdb Debug/-Y

                  copy PchPathDebug*.pdb Debug /-Y

                  注意末尾的 /-Y.第一次构建后,每个后续构建都会增量编译,因此如果再次替换文件,Visual Studio 会抱怨符号损坏.如果它们确实被损坏了,你总是可以执行重建,这将再次复制文件(这次它不会跳过它们,因为它们不再存在——清理会删除文件).

                  Note the /-Y at the end. After the first build, each subsequent build is incrementally compiled, therefore if you replace the files again, Visual Studio will complain about corrupted symbols. If they do get corrupted, you can always perform a rebuild, which will copy the files again (this time it won't skip them as they no longer exist - the cleanup deletes the files).

                  我希望这会有所帮助.我花了很长时间才能够做到这一点,但这是值得的.我有几个项目依赖于一个大框架,而且 PCH 只需要编译一次.现在所有依赖项目的编译速度都非常快.

                  I hope this helps. It took me quite some time to be able to do this, but it was worth it. I have several projects that depend on one big framework, and the PCH needs to be compiled only once. All the dependent projects now compile very quickly.

                  与其他几个人一起,我在 VS2010 下测试了这个和 VS2012 并且它似乎可以正常工作.

                  Along with several other people, I have tested this under VS2010 and VS2012 and it does appear to work properly.

                  这篇关于在 Visual Studio 中的项目之间共享预编译头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Consistent pseudo-random numbers across platforms(跨平台一致的伪随机数)
                  Vary range of uniform_int_distribution(改变uniform_int_distribution的范围)
                  What is a seed in terms of generating a random number?(就生成随机数而言,种子是什么?)
                  Is 1.0 a valid output from std::generate_canonical?(1.0 是 std::generate_canonical 的有效输出吗?)
                  Getting big random numbers in C/C++(在 C/C++ 中获取大随机数)
                  What is the best way to generate random numbers in C++?(在 C++ 中生成随机数的最佳方法是什么?)
                  <legend id='ewVBK'><style id='ewVBK'><dir id='ewVBK'><q id='ewVBK'></q></dir></style></legend>

                  <tfoot id='ewVBK'></tfoot>

                  <small id='ewVBK'></small><noframes id='ewVBK'>

                        <tbody id='ewVBK'></tbody>
                        <i id='ewVBK'><tr id='ewVBK'><dt id='ewVBK'><q id='ewVBK'><span id='ewVBK'><b id='ewVBK'><form id='ewVBK'><ins id='ewVBK'></ins><ul id='ewVBK'></ul><sub id='ewVBK'></sub></form><legend id='ewVBK'></legend><bdo id='ewVBK'><pre id='ewVBK'><center id='ewVBK'></center></pre></bdo></b><th id='ewVBK'></th></span></q></dt></tr></i><div id='ewVBK'><tfoot id='ewVBK'></tfoot><dl id='ewVBK'><fieldset id='ewVBK'></fieldset></dl></div>
                        • <bdo id='ewVBK'></bdo><ul id='ewVBK'></ul>