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.

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

目录
相关文章
|
开发工具 Android开发 iOS开发
【教程】app备案流程简单三部曲即可完成
2. 应用信息登记:开发者需要在应用商店或应用发布平台上进行应用信息登记,填写应用名称、应用版本号、应用描述、应用类型、所属类别、收费方式、开发机构、联系方式等信息。这些信息将会被展示在应用商店或应用发布平台上,供用户查看。
|
4月前
|
数据采集 安全 数据挖掘
Pandas数据合并:10种高效连接技巧与常见问题
在数据分析中,数据合并是常见且关键的步骤。本文针对合并来自多个来源的数据集时可能遇到的问题,如列丢失、重复记录等,提供系统解决方案。基于对超1000个复杂数据集的分析经验,总结了10种关键技术,涵盖Pandas库中`merge`和`join`函数的使用方法。内容包括基本合并、左连接、右连接、外连接、基于索引连接、多键合并、数据拼接、交叉连接、后缀管理和合并验证等场景。通过实际案例与技术原理解析,帮助用户高效准确地完成数据整合任务,提升数据分析效率。
384 13
Pandas数据合并:10种高效连接技巧与常见问题
|
6月前
|
关系型数据库 MySQL Linux
MySQL8官方YUM仓库使用指南
MySQL 8 是广受欢迎的开源关系数据库管理系统,引入了诸多新特性和性能提升。本文介绍如何在 Linux 上通过 MySQL 官方 YUM 仓库安装和管理 MySQL 8。首先配置 YUM 仓库并安装 MySQL,启动服务后获取临时密码并登录。接着创建数据库与用户,使用 SQL 命令创建表格、插入及查询数据。此方法简便高效,适合快速上手 MySQL 8 的基本操作。
467 13
|
3月前
|
Ubuntu 安全 数据安全/隐私保护
在Docker容器中部署GitLab服务器的步骤(面向Ubuntu 16.04)
现在,你已经成功地在Docker上部署了GitLab。这就是我们在星际中的壮举,轻松如同土豆一样简单!星际旅行结束,靠岸,打开舱门,迎接全新的代码时代。Prepare to code, astronaut!
336 12
|
4月前
|
Ubuntu Linux 测试技术
Ubuntu系统内核遭遇Kernel Panic问题
善于利用互联网资源,查找类似问题及对应解决方案。Linux社群中的各种论坛(例如 Ask Ubuntu、Ubuntu Forums和 Stack Overflow)提供很多有价值的讨论内容,可以为您排忧解难。祝您早日解决Ubuntu系统的Kernel Panic问题!
234 16
|
3月前
|
人工智能 安全 API
身份验证API的实战指南(Python & PHP 示例)
本文介绍了基于身份证信息的实名认证API,适用于金融、电商、政务、医疗等领域的身份核验场景。内容包含Python与PHP调用示例及返回结果解析,助力开发者快速集成安全合规的身份验证功能。
221 0
|
9月前
|
传感器 监控 前端开发
zabbix中IPMI (Intelligent Platform Management Interface)
zabbix中IPMI (Intelligent Platform Management Interface)
519 68
|
9月前
|
缓存 Java 测试技术
分享干货:idea常用快捷键分类总结(适合速查~~建议收藏♥)
本文以分类的形式总结了IDEA常用、好用快捷键,全是干货~
2348 1
分享干货:idea常用快捷键分类总结(适合速查~~建议收藏♥)
|
10月前
|
人工智能 自然语言处理 数据可视化
什么是AIGC?如何使用AIGC技术辅助办公?
2分钟了解AIGC技术及其如何提高日常办公效率!
3463 4
什么是AIGC?如何使用AIGC技术辅助办公?