Binding to the Most Recent Visual Studio Libraries--说的很详细,很清楚

Every version of Visual Studio comes with certain versions of the Microsoft libraries, such as the C runtime library, the MFC library, and so on. For example, Visual Studio 2008 comes with version 9.0.21022.8 of the Microsoft C runtime library and version 9.0.21022.8 of the MFC library. You can easily check which version your application needs by checking its manifest. For example: open Visual Studio 2008 and start a new MFC dialog-based application. Activate the release build configuration and build the test application. Once it is built, open a command prompt from inside Visual Studio, go to Tools > Visual Studio 2008 Command Prompt. Go to the folder containing the executable you've just built and use the following command to extract the manifest from your executable:


  1. mt.exe -inputresource:bindingtest.exe -out:manifest.txt

where bindingtest.exe is the name of your executable. The file manifest.txt will contain the exported manifest. The manifest for this test application, built using Visual Studio 2008, will look like the following:


  1. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  2. <assembly xmlns="urn:schemas-microsoft-com:asm.v1"
  3. manifestVersion="1.0">
  4. <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
  5. <security>
  6. <requestedPrivileges>
  7. <requestedExecutionLevel level="asInvoker" uiAccess="false">
  8. </requestedExecutionLevel>
  9. </requestedPrivileges>
  10. </security>
  11. </trustInfo>
  12. <dependency>
  13. <dependentAssembly>
  14. <assemblyIdentity type="win32" name="Microsoft.VC90.CRT"
  15. version="9.0.21022.8" processorArchitecture="x86"
  16. publicKeyToken="1fc8b3b9a1e18e3b">
  17. </assemblyIdentity>
  18. </dependentAssembly>
  19. </dependency>
  20. <dependency>
  21. <dependentAssembly>
  22. <assemblyIdentity type="win32" name="Microsoft.VC90.MFC"
  23. version="9.0.21022.8" processorArchitecture="x86"
  24. publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
  25. </dependentAssembly>
  26. </dependency>
  27. <dependency>
  28. <dependentAssembly>
  29. <assemblyIdentity type="win32"
  30. name="Microsoft.Windows.Common-Controls"
  31. version="6.0.0.0" processorArchitecture="x86"
  32. publicKeyToken="6595b64144ccf1df" language="*">
  33. </assemblyIdentity>
  34. </dependentAssembly>
  35. </dependency>
  36. </assembly>

What you see in this output is that your executable is dependent on the Microsoft C Runtime version 9.0.21022.8 and on the MFC library version 9.0.21022.8.

When you install the Visual Studio 2008 Service Pack 1, new versions of those libraries will be installed. However, by default, Visual Studio will keep linking to the old libraries unless you explicitly tell it to use the new versions.

How to Force Visual Studio to Bind to the New Libraries

Microsoft has defined a certain number of preprocessor definitions to tell the compiler/linker what version of the libraries to use. These definitions are also described in the MSDN. These definitions are:


  1. #define _BIND_TO_CURRENT_CRT_VERSION 1
  2. #define _BIND_TO_CURRENT_ATL_VERSION 1
  3. #define _BIND_TO_CURRENT_MFC_VERSION 1
  4. #define _BIND_TO_CURRENT_OPENMP_VERSION 1

The above defines allow you to tell the compiler/linker to use the latest version of the CRT, ATL, MFC and/or OpenMP libraries. To make it a bit easier, the following definition will bind to the latest version of all Visual Studio libraries:


  1. #define _BIND_TO_CURRENT_VCLIBS_VERSION 1

Try this in your example project. Go to Project > xyz Properties. In the project properties window, select Configuration Properties > C/C++ > Preprocessor and edit the "Preprocessor Definitions." Right now, it probably is something like this:


  1. WIN32;_WINDOWS;NDEBUG

Change this to:


  1. WIN32;_WINDOWS;NDEBUG;_BIND_TO_CURRENT_VCLIBS_VERSION=1

Close the properties window and rebuild your application. After rebuilding, extract the manifest from the Visual Studio 2008 Command Prompt.


  1. mt.exe -inputresource:bindingtest.exe -out:manifest.txt

The new manifest will look like the following:


  1. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  2. <assembly xmlns="urn:schemas-microsoft-com:asm.v1"
  3. manifestVersion="1.0">
  4. <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
  5. <security>
  6. <requestedPrivileges>
  7. <requestedExecutionLevel level="asInvoker" uiAccess="false">
  8. </requestedExecutionLevel>
  9. </requestedPrivileges>
  10. </security>
  11. </trustInfo>
  12. <dependency>
  13. <dependentAssembly>
  14. <assemblyIdentity type="win32" name="Microsoft.VC90.CRT"
  15. version="9.0.30729.1" processorArchitecture="x86"
  16. publicKeyToken="1fc8b3b9a1e18e3b">
  17. </assemblyIdentity>
  18. </dependentAssembly>
  19. </dependency>
  20. <dependency>
  21. <dependentAssembly>
  22. <assemblyIdentity type="win32" name="Microsoft.VC90.MFC"
  23. version="9.0.30729.1" processorArchitecture="x86"
  24. publicKeyToken="1fc8b3b9a1e18e3b">
  25. </assemblyIdentity>
  26. </dependentAssembly>
  27. </dependency>
  28. <dependency>
  29. <dependentAssembly>
  30. <assemblyIdentity type="win32"
  31. name="Microsoft.Windows.Common-Controls"
  32. version="6.0.0.0" processorArchitecture="x86"
  33. publicKeyToken="6595b64144ccf1df" language="*">
  34. </assemblyIdentity>
  35. </dependentAssembly>
  36. </dependency>
  37. </assembly>

Now the manifest tells you that your new application is dependent on version 9.0.30729.1 of the C Runtime and on version 9.0.30729.1 of MFC; these are the versions installed by Service Pack 1.

In real life, your application is much more complicated and will probably link to some other libraries, either third-party libraries or your own libraries. To ensure that your final application only depends on the latest version of the Visual Studio libraries, you need to make sure that all your other libraries are also only dependent on the latest version. For example, if you have a library that is still dependent on version 9.0.21022.8 of the C Runtime and you link it with your new application, your manifest might look like:


  1. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  2. <assembly xmlns="urn:schemas-microsoft-com:asm.v1"
  3. manifestVersion="1.0">
  4. <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
  5. <security>
  6. <requestedPrivileges>
  7. <requestedExecutionLevel level="asInvoker" uiAccess="false">
  8. </requestedExecutionLevel>
  9. </requestedPrivileges>
  10. </security>
  11. </trustInfo>
  12. <dependency>
  13. <dependentAssembly>
  14. <assemblyIdentity type="win32" name="Microsoft.VC90.CRT"
  15. version="9.0.30729.1" processorArchitecture="x86"
  16. publicKeyToken="1fc8b3b9a1e18e3b">
  17. </assemblyIdentity>
  18. </dependentAssembly>
  19. </dependency>
  20. <dependency>
  21. <dependentAssembly>
  22. <assemblyIdentity type="win32" name="Microsoft.VC90.MFC"
  23. version="9.0.30729.1" processorArchitecture="x86"
  24. publicKeyToken="1fc8b3b9a1e18e3b">
  25. </assemblyIdentity>
  26. </dependentAssembly>
  27. </dependency>
  28. <dependency>
  29. <dependentAssembly>
  30. <assemblyIdentity type="win32"
  31. name="Microsoft.VC90.CRT" version="9.0.21022.8"
  32. processorArchitecture="x86"
  33. publicKeyToken="1fc8b3b9a1e18e3b">
  34. </assemblyIdentity>
  35. </dependentAssembly>
  36. </dependency>
  37. <dependency>
  38. <dependentAssembly>
  39. <assemblyIdentity type="win32"
  40. name="Microsoft.Windows.Common-Controls" version="6.0.0.0"
  41. processorArchitecture="x86"
  42. publicKeyToken="6595b64144ccf1df"
  43. language="*"></assemblyIdentity>
  44. </dependentAssembly>
  45. </dependency>
  46. </assembly>

Which means it will need both version 9.0.21022.8 and version 9.0.30729.1 of the CRT.

If you are linking with libraries (.lib) files, you can use dumpbin to check what version of the libraries that lib file needs. For example:


  1. dumpbin /directives <name>.lib

The output might contain something like the following:


  1. Linker Directives
  2. -----------------
  3. /manifestdependency:"type='win32'
  4. name='Microsoft.VC90.CRT'
  5. version='9.0.21022.8'
  6. processorArchitecture='x86'
  7. publicKeyToken='1fc8b3b9a1e18e3b'"
  8. /DEFAULTLIB:"MSVCRT"
  9. /DEFAULTLIB:"OLDNAMES"

telling you it probably will force a dependency on version 9.0.21022.8 of the Microsoft CRT into your final manifest.

It's also important to know that the MSM merge modules that you can find in Program Files\Common Files\Merge Modules are updated to the new version when installing the Visual Studio 2008 service pack. This means that if your application is still dependent on the old version of the libraries and you are using the merge modules in your setup project, it will not work. In other words, if you want to keep using those merge modules, you are forced to use the latest version of the Visual Studio libraries.

In conclusion, if you want to link to the latest Visual Studio libraries, make sure all libraries that you are linking with are also using the latest version of the Visual Studio libraries.

原文地址:http://www.codeguru.com/cpp/v-s/devstudio_macros/visualstudionet/article.php/c15611/Binding-to-the-Most-Recent-Visual-Studio-Libraries.htm

时间: 2024-10-28 23:50:37

Binding to the Most Recent Visual Studio Libraries--说的很详细,很清楚的相关文章

Visual Studio对程序集签名时一个很不好用的地方

由于我们的项目底层使用到一个通过LogicalCallContext实现的上下文数据管理框架,导致所有的Unit Test不能正常运行.具体的现象在<只在UnitTest和WebHost中的出现的关于LogicalCallContext的严重问题>有过详细的介绍.解决的方案就是对相关的程序集进行强签名,并加到GAC中,是Unit Test能够识别基于LogicalCallContext项目的类型.有了Visual Studio这个强大的IDE,程序集的签名工作很好实现--仅仅需要在Projec

一起谈.NET技术,Visual Studio对程序集签名时一个很不好用的地方

由于我们的项目底层使用到一个通过LogicalCallContext实现的上下文数据管理框架,导致所有的Unit Test不能正常运行.具体的现象在<只在UnitTest和WebHost中的出现的关于LogicalCallContext的严重问题>有过详细的介绍.解决的方案就是对相关的程序集进行强签名,并加到GAC中,是Unit Test能够识别基于 LogicalCallContext项目的类型.有了Visual Studio这个强大的IDE,程序集的签名工作很好实现--仅仅需要在Proje

Visual Studio 2010中的C++ IDE增强

如果说对C++新标准的支持为Visual C++的发展奠定了坚实的基础,那么,她在IDE方面的增强,则会让她更加光彩照人. 很多Visual C++程序员都爱吃西红柿(Visual Assist).为什么?因为它可以补偿VC(Visual C++).虽然Visual C++在C++库,编译器,MFC等方面非常强大,但是她的IDE一直受到C++程序员的诟病.特别是进入 Visual Studio 2000之后,Visual C++的IDE并没有大的改变,但是效率却越来越低下,使得程序员们不得不多吃

微软Visual Studio 2010正式发布

4月12日上午,北京融京国际酒店,微软新一代开发平台Visual Studio 2010正式发布.千位中国开发菁英与世界五大城市同步迎接跨世代开发工具!微软全球资深副总裁张亚勤博士,微软大中华区开发工具及平台事业部总经理谢恩伟,微软Visual Studio商业软件部.微软亚太研发集团服务器与开发工具事业部(中国)总经理潘正磊等多位微软高层,以及来自微软总部的多位核心研发团队主管,亲临发布会现场,共同为IT专业人士解密微软新一代开发平台的革新之处. Visual Studio 2010多项革新性

用JBuilder实现类似Visual Studio的宏扩展功能

对于Visual Studio的宏,大家应该很熟悉了,这是一篇关于JBuilder实现类似Visual Studio的宏扩展功能,我们就通过对一段代码是否注释掉作为简单例子.大家可以实现自己的一些扩展,算是抛玉引砖了. 支持环境: Jbuilder 4.0 - JBuilder 7.0 使用JBuilder编译时需要在 Project ---> Project Properties ---> Required Libaries中加上Jbuilder下的 Open Tool SDK,编译成功后将

系统-Visual Studio版本问题

问题描述 Visual Studio版本问题 随着windows系统的不断升级,Visual Studio,2010-2015中哪个版本兼容性最好且实用,最早使用vc6.0时,有些地方在win7下不兼容,现在选择Visual Studio来解决这个问题,包括以后win7,win8,win0.... 解决方案 兼容性是相对的.你说VC6编的程序在Win7下不兼容,那VS2010写的程序,你拿到Win98下也不兼容. 是这样的,微软为它的操作系统提供5年的主流支持和5年的扩展支持,在主流支持阶段,微

从 Visual Studio 2017 谈起,解析微软技术生态进化之道

曾经被业界取笑「闭关锁国」的微软如今也走向了「改革开放」的道路,Visual Studio 2017的发布,不仅是VS二十周年的大事件,更是微软技术生态焕然一新的直观体验.以前只支持Windows及自家产品的微软,现在iOS.Android.Mac都支持了.写在前面 北京时间2017年3月8日凌晨,Visual Studio 2017如期发布.今年恰逢Visual Studio二十周年,Visual Studio团队可谓诚意满满.不负众望--VS2017不仅拥有全新的模块化设计和更强的性能,功能

英文版的Visual Studio.Net 2003 快捷键!

visual Visual Studio.Net 2003 Shortcut Keys Shortcut Key Description Project Shortcut Key Build.BuildSolution CTRL + SHIFT + B Builds the solution Build.Compile CTRL + F7 Creates an object file containing machine code, linker directives, sections, ex

在 Visual Studio .NET中使用Crystal Report(上) cashcho(翻译)

visual 在 Visual Studio .NET中使用Crystal Report(上) from www.aspfree.comtranslated by cash(天下第七)cashcao@msn.com 在我们开始这个关于如何在VS.NET上使用Crystal Reports的小小的研究之前,我和我的朋友都对如何把它应用于我们的Web程序中感到非常的疑惑.一个星期以后,经过一些努力(在网上查找"how-to"文档),我们掌握了将简单的报表加入asp.net程序中的一些小小技