如何强制 C++ 编译器使用特定的 CRT 版本?

2021-12-22 00:00:00 visual-c++ visual-studio-2008 c++ msvcrt

我使用 VS2008 开发 COM dll,默认使用 CRT 版本 9但我使用的是与新 CRT 不兼容的 TSF(文本服务框架).我认为解决方案是使用兼容的,那么如何指定 CRT 版本?

I am using VS2008 for developing a COM dll which by default uses CRT version 9 but I am using TSF (Text service framework) that is not compatible with the new CRT. I think the solution is to use the compatible one so how can I specify the CRT version?

推荐答案

我非常乐意加入不要手动更改您链接的 CRT 版本的建议.但是,如果出于某种原因(我无法想象)这对您来说是正确的做法,那么这样做的方法是更改?? manifest 适用于您的项目.

I whole heartily join the recommendation not to manually change the CRT version you link against. If however, for some reason (which I cannot imagine) this is the right course of action for you, the way to do so is change the manifest for your project.

首先确保不是在每次构建时生成清单(在 VS2005 上:配置属性/链接器/清单文件/生成清单),因为它会覆盖您的手动更改.还要确保在那里启用了隔离.接下来,找到清单文件 - 应位于 $(IntDir)(例如,Debug).您应该会看到类似于 -

First make sure a manifest is not generated on every build (on VS2005: Configuration properties/Linker/Manifest file/Generate manifest), as it would overwrite your manual changes. Also make sure there that isolation is enabled. Next, locate the manifest file - should be at the $(IntDir) (e.g., Debug). You should see a section similar to -

  <dependency>
    <dependentAssembly>
      <assemblyIdentity type='win32' name='Microsoft.VC80.DebugCRT' version='8.0.50727.762' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
    </dependentAssembly>
  </dependency>

(当然,对于调试版本).您需要编辑 CRT 元素的 version 和 publicKeyToken 属性.您可以检查本地 WINDOWSWinSxS 文件夹中的文件以查看可用版本.检查此处,找到后如何提取 publicKeyToken你想要的版本.(虽然我会首先尝试直接查看其他项目的清单,链接到您想要的 CRT 版本).

(For debug builds, of course). You need to edit the version and publicKeyToken attributes of the CRT element. You can inspect the files at your local WINDOWSWinSxS folder to see the versions available. Check here how to extract the publicKeyToken once you find the version you want. (Although I'd first try and look directly into manifests of other projects, linking against your desired CRT version).

如果你去那里,预计会有一些粗糙的水.如果您的应用程序是一个不与其他并行组件(MFC、OpenMP 等)链接的控制台应用程序,那么您可能会很幸运.如果您的应用程序非常重要,那么如果 SxS 组件之间没有一些复杂的版本依赖项,我会感到惊讶.

If you do go there, expect some rough water. You may have some luck if your application is a console app that does not link against other Side-by-Side components (MFC, OpenMP, etc.). If your application is non-trivial, I'd be surprised if there aren't some intricate version dependencies amont the SxS components.

(编辑)您还需要随您的应用程序分发您正在使用的特定 CRT.这是某人这样做的.

(edit) You'd also need to distribute with your application the specific CRT you're using. Here's someone who did that.

相关文章