部署 Visual C++作为私有程序集的库 DLL
此页面说明如何使用您的应用程序部署 VC++ 2008 库的本地副本,以避免安装第 3 方 vcredist。这对我很有用,因为它可以让我将压缩文件夹发送给他们可以运行的用户,而无需使用安装程序,这是不喜欢的。
但是,这对我不起作用。我的应用程序不使用 MFC,仅使用 Win32,并且是标准 C++。我有 app/MyApp.exe
,就是这样...我应该从 %PROGDIR%\Microsoft Visual Studio 9.0\VC\Redist\x86
复制哪些文件,并且准确地说他们应该去哪里?
我正在 XP 模式虚拟 PC 上对此进行测试,当我尝试按照页面中的说明进行操作时,复制文件不会导致出现“应用程序无法初始化”错误。我缺少某些步骤吗?
我查看了我的清单,似乎只使用了 CRT: http://pastebin.com/BD4NZMC2
This page has instructions how to deploy a local copy of VC++ 2008 libraries with your app, to avoid having to install 3rd-party vcredist. This is useful to me because it would let me send a zipped folder to users they can run without having to use an installer, which is disliked.
But, it doesn't work for me. My app doesn't use MFC, just Win32 and is otherwise standard C++. I have app/MyApp.exe
and that's it... which files should I be copying from %PROGDIR%\Microsoft Visual Studio 9.0\VC\Redist\x86
and exactly where should they go?
I am testing this on an XP-Mode Virtual PC and when I am trying to follow the instructions in the page, copying files across makes no change to getting the "The application failed to initialize" error. Is there some step I am missing?
I had a look at my manifest and it seems as expected only CRT is used: http://pastebin.com/BD4NZMC2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决 DLL 地狱的最简单方法是使用 /MT 编译器标志(而不是默认的 /MD)重新编译应用程序。这将静态链接 C 运行时库。
如果这是一个独立的 exe,那么这将始终有效。
如果没有(即您有自己的 DLL),则必须注意在同一模块中分配和释放内存 - 也就是说,如果您 malloc() 可执行文件中的一块内存并 free() DLL 中的同一指针,它会崩溃 - 因为可执行文件和 DLL 都会获得自己的堆,并且在不匹配的堆上尝试 free() 将不起作用。
The easiest way to workaround the DLL-hell is recompiling your application with /MT compiler flag (instead of default /MD). This will link the C runtime libs statically.
If this is a standalone exe, this will always work.
If not (i.e you have your own DLLs), you have to take care that you allocate and release memory in the same module - that is, if you malloc() a piece of memory in executable and free() the same pointer in DLL, it will crash - as both executable and DLL will get their own heaps, and attempting a free() on mismatched heap won't work.