最近在XP 32位系统上用VS2008开发的MFC Application程序在没有安装VS2008的Win7系统上双击运行以后出现了“应用程序配置不正确, 程序无法启动”的bug。经过半天时间的研究整理出三种方案可以用来解决该问题。
方法一:对于不需要运行时函数支持的工程可以采用该方法。
(1)Project->Property->Configuration property选项下设置入下图:
(2)设置C/C++->Code Generation选项下的runtime library,对于debug版本设置为MT,对于Relese版本设置为MTd模式。
修改后保存编译即可。
对于需要运行时函数支持的工程,则需要采用方案二或三来解决。
方法二:直接下载vcredist_x86.exe(对应32位系统)或者vcredist_x64.exe(对应64位系统)在目标机上运行安装即可。安装的时候注意vcredist的版本号要与发布的exe所采用的运行时函数的版本号相同。发布的exe文件所采用的版本号即为C:\Program Files\Microsoft Visual Studio 9.0\VC\redist目录下的dll文件的版本号。
方法三:拷贝所需要的运行是函数库文件到目标机上。
查看生成exe时附带生成的 *exe.intermediate.manifest文件,比如文件的内容如下:
<?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.VC90.MFC' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
</dependentAssembly>
</dependency>
</assembly>
需要注意这个文件中的两个关键词:Microsoft.VC90.CRT,Microsoft.VC90.MFC 。
寻找到C:\Program Files\Microsoft Visual Studio 9.0\VC\redist目录,debug版本对应Debug_NonRedist目录,Release版本对应X86目录,找到上面两个关键词对应的子文件夹,拷贝他们下面所以的文件到希望发布的exe文件夹内,一同打包或拷贝到目标机上即可使用。