Microsoft Visual C++ 程序的部署

简介:

Microsoft Visual C++ 程序的部署

由Microsoft Visual C++编译的程序动态链接到C运行时(/MD 或 /MDd),它必须捆绑C运行DLL的一份拷贝(通常被叫作MSVCRT.DLL 或 MSVCRxx.DLL,其中xx代表Visual C++的版本)。

1. 用Microsoft Visual C++ 6.0编译的程序,或者发布在Windows 2000/NT/ME/98 系统
单纯通过拷贝MSVCRxx.DLL文件到应用程序目录或system32目录即可

2. 用Visual Studio 2005以上编译的程序,且发布在Windows XP及以上系统
为了减少DLL引发的配置问题(DLL hell),C和C++运行时由并行 (Side-by-Side) 程序集实现,单纯通过拷贝MSVCRxx.DLL并不足以在非开发环境正常运行程序,必须通过一个清单(manifest)来加载CRT DLL。如果加载C运行时库时没有这个清单,会引发R6034异常。这就是为何CRT DLLs现在位于WinSXS(Windows Side-by-Side)而不在System32目录的原因。

EXE和DLL文件都会有一个manifest文件,里面说明了依赖关系,用Visual Studio 2005编译后,会自动产生与可执行文件同名的manifest文件,如:
app.exe // 可执行文件
app.exe.manifest // dll依赖文件
一般情况下,会把EXE和DLL的manifest文件嵌入到EXE和DLL文件中,外置的manifest就可以删除了。如:
mt.exe /nologo /manifest ".\app.exe.manifest" /outputresource:".\app.exe";1
在EXE文件中,最后面的值为1,在DLL文件中,值为2
Microsoft Visual C++运行库DLL文件中则没有嵌入manifest文件,因此需要外部的manifest文件,Visual Studio 2005的manifest名字叫Microsoft.VC80.CRT.manifest,Visual Studio 2008的manifest名字叫Microsoft.VC90.CRT.manifest,所以要将Microsoft.VC80.CRT.manifest,MSVCR80.dll,MSVCP80.dll,MSVCM80.dll 这四个文件拷贝到应用程序目录。如
C:\Test\app.exe
C:\Test\MSVCR80.dll
C:\Test\MSVCP80.dll
C:\Test\MSVCM80.dll
C:\Test\Microsoft.VC80.CRT.Manifest
或者采用Microsoft官方建议,如:
在WinXP以上
C:\Test\app.exe
C:\Test\Microsoft.VC80.CRT\Microsoft.VC80.CRT.manifest
C:\Test\Microsoft.VC80.CRT\msvcr80.dll
C:\Test\Microsoft.VC80.CRT\msvcp80.dll
C:\Test\Microsoft.VC80.CRT\msvcm80.dll
在Win2K以下
C:\Test\app.exe
C:\Test\msvcr80.dll
C:\Test\msvcp80.dll
C:\Test\msvcm80.dll
如果用以上方法还是不能执行,说明Microsoft Visual C++在系统中有多个版本的DLL,程序用到的和发布的Microsoft Visual C++ DLL不匹配,如:
app.Manifest 文件,要求Microsoft.VC90.CRT的DLL,并且版本为9.0.21022.8

<?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' />
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly>
<assemblyIdentity type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*' />
</dependentAssembly>
</dependency>
</assembly>


Microsoft.VC90.CRT.manifest文件,指明是Microsoft.VC90.CRT,但版本为9.0.30729.1

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<noInheritable></noInheritable>
<assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.30729.1" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
<file name="msvcr90.dll" hashalg="SHA1" hash="9785b1c493deb5b2134dc4aef3719cee207001bc"><asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"><dsig:Transforms><dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform></dsig:Transforms><dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod><dsig:DigestValue>VF5ECUAHPV7EnUf+/UIXMPizPvs=</dsig:DigestValue></asmv2:hash></file> <file name="msvcp90.dll" hashalg="SHA1" hash="0f6bbf7fe4fb3fca2cb5b542eca1a1cad051f01c"><asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"><dsig:Transforms><dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform></dsig:Transforms><dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod><dsig:DigestValue>3Wg+StVMq2uhx7POnAkl2w4dDmY=</dsig:DigestValue></asmv2:hash></file> <file name="msvcm90.dll" hashalg="SHA1" hash="7f3290ab2b7444c2b4a9b1fedfdb16466d7a21bb"><asmv2:hash xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"><dsig:Transforms><dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity"></dsig:Transform></dsig:Transforms><dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></dsig:DigestMethod><dsig:DigestValue>/YfRn7UQENzdMeoMHxTgdRMiObA=</dsig:DigestValue></asmv2:hash></file>
</assembly>


二者版本不一致,导致程序不能运行,解决办法是发布程序要求的9.0.21022.8版本的Microsoft.VC90.CRT文件

3. 还有一种简单办法是在需要部署的机器上安装Visual C++ 2008 Redistributable Package(x86)或者(x64)。
Microsoft Visual C++ 2005 SP1 下载:
http://download.microsoft.com/download/7/9/8/798325b7-8993-4ef9-9148-8db9ff4187fc/vcredist_x86.exe



本文转自94cool博客园博客,原文链接:http://www.cnblogs.com/94cool/archive/2010/04/30/1724659.html,如需转载请自行联系原作者
相关文章
|
3天前
|
运维 Serverless Go
Serverless 应用引擎产品使用之在阿里云函数计算中c++模板,将编译好的C++程序放进去部署如何解决
阿里云Serverless 应用引擎(SAE)提供了完整的微服务应用生命周期管理能力,包括应用部署、服务治理、开发运维、资源管理等功能,并通过扩展功能支持多环境管理、API Gateway、事件驱动等高级应用场景,帮助企业快速构建、部署、运维和扩展微服务架构,实现Serverless化的应用部署与运维模式。以下是对SAE产品使用合集的概述,包括应用管理、服务治理、开发运维、资源管理等方面。
9 1
|
7天前
|
安全 编译器 C++
C++从入门到精通:3.2异常处理——掌握C++的异常处理机制,提高程序健壮性
C++从入门到精通:3.2异常处理——掌握C++的异常处理机制,提高程序健壮性
|
7天前
|
存储 IDE 编译器
C++从入门到精通:1.3.1了解IDE与C++程序的编写、编译和运行
C++从入门到精通:1.3.1了解IDE与C++程序的编写、编译和运行
|
7天前
|
存储 程序员 数据库
C++从入门到精通:1.2.2简单程序与接收用户输入
C++从入门到精通:1.2.2简单程序与接收用户输入
|
7天前
|
存储 编译器 C++
C++从入门到精通:1.2.1简单程序编写与基本操作
C++从入门到精通:1.2.1简单程序编写与基本操作
|
21小时前
|
编译器 C语言 C++
c++初阶------类和对象(六大默认构造函数的揭破)-3
c++初阶------类和对象(六大默认构造函数的揭破)
|
21小时前
|
编译器 C语言 C++
c++初阶------类和对象(六大默认构造函数的揭破)-2
c++初阶------类和对象(六大默认构造函数的揭破)
|
21小时前
|
存储 编译器 C语言
c++初阶------类和对象(六大默认构造函数的揭破)-1
c++初阶------类和对象(六大默认构造函数的揭破)
|
22小时前
|
存储 编译器 C语言
c++初阶-------类和对象-2
c++初阶-------类和对象
|
22小时前
|
编译器 C语言 C++
c++初阶-------类和对象-1
c++初阶-------类和对象