我使用 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.
最终可执行文件必须在 Release模式下编译并使用这些DLL的发布版本。不要给出调试二进制文件。由于出于调试目的而添加的逻辑,它们非常慢
实际上您并不需要发送 DLL,但您应该告诉用户安装相应的 VC redistributable package 。这是runtime ( CRT ) 适用于包含 printf
、memcpy
... 等函数的 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/