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:
- 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:
- <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
- <assembly xmlns="urn:schemas-microsoft-com:asm.v1"
- manifestVersion="1.0">
- <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
- <security>
- <requestedPrivileges>
- <requestedExecutionLevel level="asInvoker" uiAccess="false">
- </requestedExecutionLevel>
- </requestedPrivileges>
- </security>
- </trustInfo>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type="win32" name="Microsoft.VC90.CRT"
- version="9.0.21022.8" processorArchitecture="x86"
- publicKeyToken="1fc8b3b9a1e18e3b">
- </assemblyIdentity>
- </dependentAssembly>
- </dependency>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type="win32" name="Microsoft.VC90.MFC"
- version="9.0.21022.8" processorArchitecture="x86"
- publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
- </dependentAssembly>
- </dependency>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type="win32"
- name="Microsoft.Windows.Common-Controls"
- version="6.0.0.0" processorArchitecture="x86"
- publicKeyToken="6595b64144ccf1df" language="*">
- </assemblyIdentity>
- </dependentAssembly>
- </dependency>
- </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:
- #define _BIND_TO_CURRENT_CRT_VERSION 1
- #define _BIND_TO_CURRENT_ATL_VERSION 1
- #define _BIND_TO_CURRENT_MFC_VERSION 1
- #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:
- #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:
- WIN32;_WINDOWS;NDEBUG
Change this to:
- 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.
- mt.exe -inputresource:bindingtest.exe -out:manifest.txt
The new manifest will look like the following:
- <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
- <assembly xmlns="urn:schemas-microsoft-com:asm.v1"
- manifestVersion="1.0">
- <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
- <security>
- <requestedPrivileges>
- <requestedExecutionLevel level="asInvoker" uiAccess="false">
- </requestedExecutionLevel>
- </requestedPrivileges>
- </security>
- </trustInfo>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type="win32" name="Microsoft.VC90.CRT"
- version="9.0.30729.1" processorArchitecture="x86"
- publicKeyToken="1fc8b3b9a1e18e3b">
- </assemblyIdentity>
- </dependentAssembly>
- </dependency>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type="win32" name="Microsoft.VC90.MFC"
- version="9.0.30729.1" processorArchitecture="x86"
- publicKeyToken="1fc8b3b9a1e18e3b">
- </assemblyIdentity>
- </dependentAssembly>
- </dependency>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type="win32"
- name="Microsoft.Windows.Common-Controls"
- version="6.0.0.0" processorArchitecture="x86"
- publicKeyToken="6595b64144ccf1df" language="*">
- </assemblyIdentity>
- </dependentAssembly>
- </dependency>
- </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:
- <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
- <assembly xmlns="urn:schemas-microsoft-com:asm.v1"
- manifestVersion="1.0">
- <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
- <security>
- <requestedPrivileges>
- <requestedExecutionLevel level="asInvoker" uiAccess="false">
- </requestedExecutionLevel>
- </requestedPrivileges>
- </security>
- </trustInfo>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type="win32" name="Microsoft.VC90.CRT"
- version="9.0.30729.1" processorArchitecture="x86"
- publicKeyToken="1fc8b3b9a1e18e3b">
- </assemblyIdentity>
- </dependentAssembly>
- </dependency>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type="win32" name="Microsoft.VC90.MFC"
- version="9.0.30729.1" processorArchitecture="x86"
- publicKeyToken="1fc8b3b9a1e18e3b">
- </assemblyIdentity>
- </dependentAssembly>
- </dependency>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type="win32"
- name="Microsoft.VC90.CRT" version="9.0.21022.8"
- processorArchitecture="x86"
- publicKeyToken="1fc8b3b9a1e18e3b">
- </assemblyIdentity>
- </dependentAssembly>
- </dependency>
- <dependency>
- <dependentAssembly>
- <assemblyIdentity type="win32"
- name="Microsoft.Windows.Common-Controls" version="6.0.0.0"
- processorArchitecture="x86"
- publicKeyToken="6595b64144ccf1df"
- language="*"></assemblyIdentity>
- </dependentAssembly>
- </dependency>
- </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:
- dumpbin /directives <name>.lib
The output might contain something like the following:
- Linker Directives
- -----------------
- /manifestdependency:"type='win32'
- name='Microsoft.VC90.CRT'
- version='9.0.21022.8'
- processorArchitecture='x86'
- publicKeyToken='1fc8b3b9a1e18e3b'"
- /DEFAULTLIB:"MSVCRT"
- /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.
Binding to the Most Recent Visual Studio Libraries--说的很详细,很清楚的更多相关文章
- 在Chrome+Visual Studio中调试asp.net程序很慢的问题(Firefox也有类似问题)
在Chrome+Visual Studio中调试asp.net程序很慢的问题(Firefox也有类似问题) 今天开始起在Chrome中调试,发现问题主要出在菜单栏(layout文件)中,google了 ...
- Visual Studio 2019连接MySQL数据库详细教程
前言 如果要在 Visual Studio 2019中使用MySQL数据库,首先需要下载MySQL的驱动 Visual Studio默认只显示微软自己的SQL Server数据源,点击其它也是微软自己 ...
- Visual Studio 控件命名规范(很详细)
VS 控件命名规范 Type Prefix Example Array arr arrShoppingList Boolean bln blnIsPostBack Byte byt bytPixelV ...
- docker4dotnet #3 在macOS上使用Visual Studio Code和Docker开发asp.net core和mysql应用
.net猿遇到了小鲸鱼,觉得越来越兴奋.本来.net猿只是在透过家里那田子窗看外面的世界,但是看着海峡对岸的苹果园越来越茂盛,实在不想再去做一只宅猿了.于是,.net猿决定搭上小鲸鱼的渡轮到苹果园去看 ...
- Visual Studio 2015 各版本对比及下载地址
2015年7月20日23时30分,微软举行了Visual Studio 2015的发布会,跟随者Visual Studio 2015 而来的是,.net 开源,C#支持wp,ios,android三大 ...
- 2014 Visual Studio Contact(); 直播笔记
昨天微软干了几件了不起的事:.NET开发环境将开源.跨平台支持(Mac OS X和Linux).多设备支持(WP.Android和iOS)和Visual Studio免费(Visual Studio ...
- Visual Studio 2010 插件之Resharper
这一系列不是对每个功能的中文帮助,而是我对开发中可能涉及的功能需求,利用Resharper来完成.有些是Visual Studio有的,但是做的不好,有些是没有而Resharper发明的.总的目的都只 ...
- 【译】Visual Studio 15 预览版更新说明
序:恰逢Build2016大会召开,微软发布了VS2015的update2更新包和VS2016预览版.本人正在提升英文水平中,于是在这里对VS2016预览版的官方文档进行了部分翻译.因为VS有些功能使 ...
- Microsoft Visual Studio 6.0 Enterprise Edition
我们的老古董啊 啊啊啊 啊啊 <Microsoft Visual Studio 6.0 Enterprise Edition>(完整9CD,带中文MSDN& <Micr ...
随机推荐
- ios开发----视图的生命周期
熟悉web开发的朋友可能对页面page的生命周期有一定的了解和认识,正如web开发中的页面生命周期一样,移动客户端开发也有它自己的生命周期.下文将说明ios开发中视图的生命周期既运行顺序. 在ios视 ...
- select2 取值 赋值
项目中心引入了select2的插件.优势:可以多选.搜索,缺点:存取值不如select方便. select2 取值: <script type="text/javascript&quo ...
- Javascript基本格式
Javascript基本格式 ① JavaScript区分大小写 只要一门语言是面向对象的,其都是区分大小写,所以在Javascript中,变量小i与变量I是两个完全不同的变量 ② JavaScrip ...
- 如何找到Linux下常用命令的源码
Linux系统,常用命令的来源很多,有些命令是shell自带的,比如cd,通过执行help命令,可以查看当前系统所有的内置命令. 用type <cmd_name>来查看一个命令是否为内置命 ...
- CSS样式display:none和visibility:hidden的区别
同样是隐藏,display:none与visibility:hidden有什么区别呢? 虽然display:none与visibility:hidden都能达到隐藏可见元素的作用(视觉上),但事实上, ...
- OWIN and Katana - 1
翻译自 http://www.asp.net/aspnet/overview/owin-and-katana/an-overview-of-project-katana 十多年来,基于ASP.NET框 ...
- 用AJAX自定义日历
需求分析 在一些购物网站中,都会有促销活动,这些活动都在日历上标注出来,如何通过Ajax让日历 通过读取数据库中的信息,正确的把促销活动标注在日历上,本文通过自定义日历来实现这 个问题. 技术难点 日 ...
- MySql 服务端与客户端下载地址
mysql官网的注册,要上传户口,才能下载. 在网上搜了个下载地址. mysql-5.6.8-rc http://mysql.stu.edu.tw/Downloads/MySQL-5.6/mysql- ...
- 一个例子说明如何在DataSnap中使用FireDAC
一.FireDAC调用DataSnap远程方法查询数据示例 1.服务端使用FDQUERY查询数据并返回TDATASET: function TServerMethods1.GetData(var sq ...
- sizeof的用法的一些归纳
1 sizeof 是运算符,不是函数 2 sizeof 不能求得void类型的长度,能求得 void*类型的指针的长度 sizeof(void) 会导致编译错误.因为声明一个变量的最重要的作用就是告诉 ...