vs2005及以上版本的程序分发问题
我们使用vs2005及以上版本编译的应用程序(C/C++),在客户机器运行时,会出现:
“由于应用程序的配置不正确,应用程序未能启动,重新安装应用程序可能会纠正这个问题”
那么,我们怎么解决这个问题呢?
我们知道,使用VC编译C/C++程序,都需要相关的C runtime库才能运行。
下表为VC6以上版本使用C运行库情况:
VS版本 | VC版本 | C运行库 |
VS98 | 6.0 | msvcr.dll |
VS2003 | 7.1 | msvcr71.dll |
VS2005 | 8.0 | msvcr80.dll |
VS2008 | 9.0 | msvcr90.dll |
VS2010 | 10.0 | msvcr10.dll |
用VS2003以上版本的IDE编译的应用程序,怎么发布给最终用户呢?
(1)IDE默认
找到vcredist_x86.exe文件,随应用程序分发下去。
这个vcredist_x86.exe需要用户独立安装。
安装完,在“添加或删除程序”中会出现:
VS版本 | 显示名称(添加或删除程序) |
VS2005 | Microsoft Visual C++ 2005 Redistributable |
VS2008 | Microsoft Visual C++ 2008 Redistributable - x86 xxx |
VS2010 | Microsoft Visual C++ 2010 x86 Redistributable - xxx |
注意:我们分发的vcredist_x86.exe文件,一定要拷贝开发机器上的!
(例如,VS2005的vcredist_x86.exe文件,
在我机器上的位置:C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\vcredist_x86\vcredist_x86.exe)
(2)VC6模式
(英文版本的IDE)
a. 设置使用静态MFC
"Project" -> "Properties" -> "Configuration Properties" -> "General"
把"Use of MFC"设置为"Use MFC in a Static Library"
b. 设置运行库为MT
"Project" -> "Properties" -> "Configuration Properties" -> "C/C++" -> "Code Generation"
把"Runtime Library"设置为"Multi-threaded (/MT)"
参考文章:http://waterlin.blog.35.cn/articles/how-to-compile-static-link-library-program-in-vc2008.html(细节之锤)