在未安装VS2005的机器上运行VS2005编译的C++程序

1. 问题描述:

最近在VS2005下用C++写了一个Console程序,在一台未安装VS2005的机器上不能正常运行。
用命令行方式运行,提示:
“系统无法执行指定的程序”
直接双击运行,提示:
“由于应用程序的配置不正确,应用程序未能启动,重新安装应用程序可能会纠正这个问题”

用VC6和VS2003也有这个问题,只不过会提示说找不到“***.dll”,把需要的dll拷贝到目标机器就可以正常运行了。而VS2005并没有提示缺少哪些dll。

2. 解决方案:

在水木C++版请教了一下,ass做出了回答(非常感谢ass的帮助)。把他的回答摘录如下,大家共同学习:

“因为没有msvcr80.dll
可以改一下编译选项 多线程dll(/MD)改成多线程(MT)这样就静态链接,
也可以从你的vc8安装盘上找到再分发包vcredist_xxx.exe和你的程序捆绑安装。”

根据ass指导的思路,自己实验了一下,感觉以下两种解决办法是比较方便的:

方法一:
在C:/Program Files/Microsoft Visual Studio 8/VC/redi
st/Debug_NonRedist/x86/Microsoft.VC80.DebugCRT 下找到了下列文件:

msvcm80d.dll
msvcp80d.dll
msvcr80d.dll
Microsoft.VC80.DebugCRT.manifest

把这几个文件拷贝到目标机器上,与运行程序同一文件夹或放到system32下,就可以运行那个程序了。

方法二:
修改“C++/Code Generation”中的运行时库选项,将/MD或/MDd 改为 /MT或/MTd,这样就实现了对VC运行时库的静态链接,在运行时就不再需要VC的dll了。

 

 

 

 

 

 

 

 

 

 

 

 

http://blog.csdn.net/liguangyi/archive/2006/06/01/767396.aspx
【转贴】VS2005的程序文件分发问题及解决

VC2005 编译出来的程序文件,采用了manifest方式来指定dll文件。对于win98、win2000系统,把exe文件和VC的 dll连接库放到一起就成了。对于winxp、win2003系统就要麻烦的多了,VC的连接库默认是被放到了winsxs目录下,结果造成在这些系统 上,直接拷贝exe文件,往往是不能运行(找不到msvcr80.dll、mfc80.dll文件等),或者在事件日志中报错。

解决方式:
方式一、在目标系统上安装2005版vcredist_x86.exe。

方式二、直接拷贝VS8目录下的VC / redist / x86 / 目录下的 Microsoft.VC80.MFC、Microsoft.VC80.CRT、Microsoft.VC80.MFCLOC几个文件夹,到exe所在的目录下,目录结构如下:
./myapp.exe
./myapp.dll
./Microsoft.VC80.CRT/
./Microsoft.VC80.MFC/
./Microsoft.VC80.MFC/Microsoft.VC80.MFCLOC/
然后修改Microsoft.VC80.MFCLOC目录下的Microsoft.VC80.MFCLOC.manifest文件,将其中的version="8.0.50727.42",修改为version="8.0.50608.0"。


方式二的目录结构,在xp和2003下是没有问题的,但是在win98/win2000中,因为exe和dll不在同一目录下,就会出现找不到dll的问题。

有什么更好的解决呢?呵呵,国外的一个大牛(http://blog.kalmbachnet.de)找到一绝招:

方式三、
1、首先编译myapp.exe的时候,在配置中,选择生成单独的manifest文件,如:myapp.exe.manifest。
2、将myapp.exe、myapp.exe.manifest拷贝到一个目录下
3、将Microsoft.VC80.MFC、Microsoft.VC80.CRT、Microsoft.VC80.MFCLOC几个目录下的文件,都拷贝到myapp.exe所在的目录下。
4、将Microsoft.VC80.MFCLOC.manifest文件中的version="8.0.50727.42",修改为version="8.0.50608.0"。
5、编辑myapp.exe目录下的所有 .manifest文件,将文件中的publicKey键值删除,一般是publicKeyToken="1fc8b3b9a1e18e3b"
6、然后运行myapp.exe看看,嗯。


Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=767396
 

【转贴】How to bypass the WinSxS for CRT/MFC/ATL DLLs

Starting with VC8, you have two options to distribute the DLL version of the CRT/MFC/ATL with your application:

You can redistribute the DLLs with your application in the same directory and also put a valid manifest for these DLLs into this directory
You can install the redist.exe and the DLL will be installed in the WinSxS folder (on XP and later)
So, if you want to be independed from global DLLs, you might think that you can simply put the DLLs into your applications directory. But this is a false conclusion.
If a DLL is installed in the WinSxS folder, the local DLLs will be ignored. This might be even true, if a newer DLL was installed (for example by security hotfixes). This is possible due to policy redirections of these SxS-DLLs.
In most cases this also makes sense, because you always get the latest (hopefully compatible) version of the DLL.

But there might be some situations in which you might have full control over which DLLs are loaded from where. Now, Andre Stille (an other VC++ MVP), found a very simple solution : just remove the “publicKeyToken” attribute from the manifests!
So an application manifest looks like:

Application.exe.manifest:


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1&quo
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值