一直以来在做一个跟某研究所合作的项目,今天,要到研究所那边演示程序。于是,一直以来没有在意的程序发布问题,成了病患。什么动态库都考全了,结果到研究所那边运行,弹出如下窗口:
这下把我吓的。后来到网上查找资料,才解决此问题。同时,在找资料解决问题的同时,也学习了一下*.exe.manifest文件。这个文件其实就是引导windows装载器为exe加载什么样的运行时库。其他的,没具体研究过。
用vs2008打开exe文件,结果如下:
点击英语(美国)。查看具体的manifest文件内容。(其实说是manifest文件,这个文件存放在exe中的资源段)
点击进入后,看到一些配置信息:
<?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"
<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" language="*"></assemblyIdentity>
</dependentAssembly>
</dependency>
</assembly>
</dependentAssembly>
</dependency>
</assembly>
关键的地方在红色字段。意思是exe类型是win32可执行程序,运行时库是
Microsoft.VC90.CRT,版本是9.0.21022.8。 处理器架构是X86。现在明白了,要把exe放到其他机器上运行,必要的运行时库是vs2008里面的一个目录Microsoft.VC90.CRT里面的所有dll。于是打包发布的时候,要把Microsoft.VC90.CRT里面的所有dll拷贝到发布的文件夹里面同时发布。于是,问题解决了。
最后说明的是,如果manifest里面还有
<assemblyIdentity type="win32" name="Microsoft.VC90.DebugCRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
则还要把vs2008下面的Microsoft.VC90.DebugCRT目录下面的所有dll同时发布。如果有其他的类似信息,类似的发布dll。
最后,个人总结:
对于编译参数,不同的运行时库如下:
/MT 什么运行时库都不要
/MTd 要Microsoft.VC90.CRT
/Md 需要Microsoft.VC90.DebugCRT和Microsoft.VC90.CRT 如果是release版 只要Microsoft.VC90.CRT
/MDd 需要Microsoft.VC90.DebugCRT
/MTd 要Microsoft.VC90.CRT
/Md 需要Microsoft.VC90.DebugCRT和Microsoft.VC90.CRT 如果是release版 只要Microsoft.VC90.CRT
/MDd 需要Microsoft.VC90.DebugCRT