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

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

  1. 在Chrome+Visual Studio中调试asp.net程序很慢的问题(Firefox也有类似问题)

    在Chrome+Visual Studio中调试asp.net程序很慢的问题(Firefox也有类似问题) 今天开始起在Chrome中调试,发现问题主要出在菜单栏(layout文件)中,google了 ...

  2. Visual Studio 2019连接MySQL数据库详细教程

    前言 如果要在 Visual Studio 2019中使用MySQL数据库,首先需要下载MySQL的驱动 Visual Studio默认只显示微软自己的SQL Server数据源,点击其它也是微软自己 ...

  3. Visual Studio 控件命名规范(很详细)

    VS 控件命名规范 Type Prefix Example Array arr arrShoppingList Boolean bln blnIsPostBack Byte byt bytPixelV ...

  4. docker4dotnet #3 在macOS上使用Visual Studio Code和Docker开发asp.net core和mysql应用

    .net猿遇到了小鲸鱼,觉得越来越兴奋.本来.net猿只是在透过家里那田子窗看外面的世界,但是看着海峡对岸的苹果园越来越茂盛,实在不想再去做一只宅猿了.于是,.net猿决定搭上小鲸鱼的渡轮到苹果园去看 ...

  5. Visual Studio 2015 各版本对比及下载地址

    2015年7月20日23时30分,微软举行了Visual Studio 2015的发布会,跟随者Visual Studio 2015 而来的是,.net 开源,C#支持wp,ios,android三大 ...

  6. 2014 Visual Studio Contact(); 直播笔记

    昨天微软干了几件了不起的事:.NET开发环境将开源.跨平台支持(Mac OS X和Linux).多设备支持(WP.Android和iOS)和Visual Studio免费(Visual Studio ...

  7. Visual Studio 2010 插件之Resharper

    这一系列不是对每个功能的中文帮助,而是我对开发中可能涉及的功能需求,利用Resharper来完成.有些是Visual Studio有的,但是做的不好,有些是没有而Resharper发明的.总的目的都只 ...

  8. 【译】Visual Studio 15 预览版更新说明

    序:恰逢Build2016大会召开,微软发布了VS2015的update2更新包和VS2016预览版.本人正在提升英文水平中,于是在这里对VS2016预览版的官方文档进行了部分翻译.因为VS有些功能使 ...

  9. Microsoft Visual Studio 6.0 Enterprise Edition

    我们的老古董啊  啊啊啊 啊啊 <Microsoft Visual Studio 6.0 Enterprise Edition>(完整9CD,带中文MSDN&   <Micr ...

随机推荐

  1. php中preg_match用户名正则实例

    例子,字母.数字和汉字  代码如下 复制代码 if(preg_match("/[ '.,:;*?~`!@#$%^&+=)(<>{}]|]|[|/|\|"||/& ...

  2. 原生JS面向对象思想封装轮播图组件

    原生JS面向对象思想封装轮播图组件 在前端页面开发过程中,页面中的轮播图特效很常见,因此我就想封装一个自己的原生JS的轮播图组件.有了这个需求就开始着手准备了,代码当然是以简洁为目标,轮播图的各个功能 ...

  3. css笔记——关于 body/html 的高度百分比

    body{  height:100%;  视窗的高度 min-height:100%;文档的具体高度} 这两个百分比的具体高度在页脚永远放在文档底部非常重要,此时用min-height:100% 具体 ...

  4. html5笔记

    出处:http://www.cnblogs.com/xiaowei0705/archive/2011/04/19/2021372.html HTML5 LocalStorage 本地存储 HTML5  ...

  5. 绝对URL和相对URL

    什么是URL? 应用举例:可以是图片等资源地址,浏览器地址栏的网址等等 Uniform Resource Locator 统一资源定位符 http://www.123.com/infor/index. ...

  6. 【转】winform与web 按钮button去掉边框

    ref:http://blog.csdn.net/wangzh300/article/details/5264316 WinForm的话 设置Button属性的FlatStyle为Flat,并且设置F ...

  7. 玩转Slot Machine

    最近在做一个有关Slot  Machine小游戏的开发,其中遇到了不少的坑,现将个人遇到的问题总结如下,希望今后对大家开发的过程中有所的帮助. 这个项目是部署到微信朋友圈广告的,两天时间,PV就有14 ...

  8. Android 生命周期 和 onWindowFocusChanged

    转载 http://blog.csdn.net/pi9nc/article/details/9237031 onWindowFocusChanged重要作用 Activity生命周期中,onStart ...

  9. ES6学习笔记(一)

    1.let命令 基本用法 ES6新增了let命令,用来声明变量.它的用法类似于var,但是所声明的变量,只在let命令所在的代码块内有效. { let a = 10; var b = 1; } a / ...

  10. Apache+PHP+MySql 的安装及配置

    每一项技术用的人多了,就会有人将其进行优化,做成一个简单.实用.大众化的工具,这对于初识者来说是非常方便的,但是对于长久学习或工作这方面的人技术人员来说是不可取的,所以还是要学习基础的实用方法.因此, ...