Visual Studio 2019 能否将所需的 DLL 打包到一个小的 .exe 文件中?

标签 c visual-studio dll software-distribution

我使用 Visual Studio 2019 使用 C++ WinAPI 制作了一个 Windows 应用程序。 完成后,我构建了它,并在我的计算机上执行。它工作完美。 然后我发给我没有Visual Studio的 friend 。它说需要“msvcp140d.dll”“ucrtbased.dll”“vcruntime140_1d.dll”“vcruntime140d.dll”才能打开它。

然后我在我的计算机中找到它们,将它们与我的应用程序放在同一目录中,然后将它们发送给我的 friend 。效果也很好。

但我的问题是“有什么方法可以仅使用 Visual Studio 2019 来打包它们吗?”具有大量 DLL 的小型应用程序有点奇怪。

最佳答案

首先,您发送了错误的文件。 带有 d 后缀的文件仅用于调试并且不得分发

You cannot redistribute all of the files that are included in Visual Studio; you are only permitted to redistribute the files that are specified in Redist.txt or the online "REDIST list." Debug versions of applications and the various Visual C++ debug DLLs are not redistributable. For more information, see Choosing a Deployment Method.

Determining Which DLLs to Redistribute

最终可执行文件必须在 Release模式下编译并使用这些DLL的发布版本。不要给出调试二进制文件。由于出于调试目的而添加的逻辑,它们非常慢

实际上您并不需要发送 DLL,但您应该告诉用户安装相应的 VC redistributable package 。这是runtime ( CRT ) 适用于包含 printfmemcpy... 等函数的 Visual Studio 项目。如果项目中不使用任何DLL,则无需查找任何其他DLL

还可以通过changing the option /MD to /MT静态链接运行时库。这样,最终的 exe 文件将是独立的(不需要额外的运行时 DLL),但它也会更大,并且当更新包以修复错误或性能问题时,您将无法使用较新的库函数。同样,无论您是静态链接还是动态链接,都必须在 Release模式下编译

另请参阅

关于Visual Studio 2019 能否将所需的 DLL 打包到一个小的 .exe 文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59234416/

相关文章:

asp.net - 更新 ASP.NET Web 应用程序 DLL 的最佳方法是什么?

c - 奇怪的运行时问题 : printf stops working midway

c - 为什么我的右移运算符在 c 中按逻辑而不是算术运行?

c - 获取 TCHAR 的 Unicode 值

visual-studio - "Missing Authentication Token"错误

c# - FreeLibrary 在使用 GetModuleFileName(x64 平台)后抛出 AccessViolationException?

c++ - 为 gcc 启用核心转储是否需要 -g?

c - 用C程序编写具有一定约束的GUESS游戏。发生的问题-代码错误,代码逻辑,建议

visual-studio - Visual Studio 中类似代码图的交互式流程图

windows - 找不到 Visual Studio 2017 依赖的 .dll