如何执行 C++ 编译器使用特定的CRT版本?
我正在使用 VS2008 开发 COM dll,默认情况下使用 CRT 版本 9 但我使用的 TSF(文本服务框架)与新的 CRT 不兼容。 我认为解决方案是使用兼容的那么我如何指定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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我完全同意不手动更改链接的 CRT 版本的建议。 但是,如果出于某种原因(我无法想象)这对您来说是正确的行动方案,则方法是更改 您的项目的清单。
首先确保不会在每个构建中生成清单(在 VS2005 上:配置属性/链接器/清单文件/生成清单),因为它会覆盖您的手动更改。 还要确保启用了隔离。
接下来,找到清单文件 - 应位于 $(IntDir)(例如,调试)。 您应该看到类似于 - 的部分
(当然,对于调试版本)。 您需要编辑 CRT 元素的版本和 publicKeyToken 属性。
您可以检查本地 WINDOWS\WinSxS 文件夹中的文件以查看可用的版本。 检查此处找到后如何提取 publicKeyToken您想要的版本。 (尽管我首先尝试直接查看其他项目的清单,链接到您所需的 CRT 版本)。
如果你真的去那里,预计会有一些汹涌的水。 如果您的应用程序是一个不与其他并排组件(MFC、OpenMP 等)链接的控制台应用程序,那么您可能会很幸运。 如果您的应用程序很重要,那么 SxS 组件中没有一些复杂的版本依赖关系,我会感到惊讶。
(编辑)您还需要与您的应用程序一起分发您正在使用的特定 CRT。 这是某人这样做的。
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.
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 -
(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 WINDOWS\WinSxS 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).
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.
(edit) You'd also need to distribute with your application the specific CRT you're using. Here's someone who did that.
最简单的方法是使用与 TFS 兼容的 CRT 的 VC++ 版本构建 DLL。
我认为将 DLL 与不同版本的 CRT 链接不是一个好主意,除非您也使用相同版本的头文件。 最简单的方法是使用正确的 VC++ 版本...
如果您仍然想尝试,可以:
您也可以尝试更改“工具->选项->项目和解决方案->VC++目录->库文件”中的默认目录。 也许将 $(VCInstallDir)lib 更改为其他版本的 CRT 所在的路径即可解决问题
The easiest way will be to build your DLL with a VC++ version that uses the CRT that is compatible with TFS.
I don't think that it is a good idea just to link your DLL with a different version of the CRT, unless you also use the same version of the header files. And the easiest way to do that will be to use the right VC++ version...
If you still want to try, you can:
You can also try to change the default directories in "Tools->Options->Projects and solution->VC++ directories->library files". Maybe changing $(VCInstallDir)lib to the path where you other version of the CRT resides will do the trick
不要尝试使用 VS9 并链接到其他版本的 CRT。
如果您需要您的应用程序链接到另一个 CRT,例如 VS8 的 CRT,那么您必须编译并编译它。 在该版本的 VS 中链接您的应用程序。
Don't try to use VS9 and link to another version of the CRT.
If you need your app to link to another CRT, say VS8's CRT, then you must compile & link your app in that version of VS.
该解决方案适用于我使用 Visual Studio Express 2013 x64 + OpenCV 2.4.9 x64 编译、调试(我将其集成到 LV2013 x64 中),但它应该适用于任何其他 VS 版本:
1)右键单击您的解决方案 > 属性> 调试源文件...
2) 可能有两个完整的文件(取决于您的 VS 安装目录)...
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\vc7\atlmfc
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\vc7\crt
有了这些,它适用于 Visual Studio 2013 Express,但也适用于其他 2013。如果您有 Visual Studio 10 或 11在每个中键入“Microsoft Visual Studio 11.0”或10.0。 您也可以只添加它们。
您可以从 OpenCV.sln 的 Solution > 下获取这些条目 属性> 调试源文件(如上所述)。 正如已经描述的:CRT 需要匹配......而这发生在那个地方。
The solution worked for me with Visual Studio Express 2013 x64 + OpenCV 2.4.9 x64 compiled, debug (I integrated that in LV2013 x64), but it should work for any other VS-version:
1) Right-click on your Solution > Properties > Debug Source Files ...
2) There are maybe two entires (depending on your VS-install-directory)...
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\vc7\atlmfc
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\vc7\crt
With these it would work for Visual Studio 2013 Express but should also work for other 2013. If you've got Visual Studio 10 or 11 just type "Microsoft Visual Studio 11.0" or 10.0 in each. You can also just add them.
These entries you can get from your OpenCV.sln under Solution > Properties > Debug Source Files (as described above). And as already decribed: CRT needs to match... and this happens in that place.