Can Visual Studio 2019 pack the DLLs it requires in just a small .exe file?

ぃ、小莉子 提交于 2020-05-29 06:15:56

问题


I made a Windows application with C++ WinAPI by using Visual Studio 2019. After finishing, I built it, and executed with my computer. It works perfectly. Then I sent to my friend who didn't have Visual Studio. It said that it needs "msvcp140d.dll" "ucrtbased.dll" "vcruntime140_1d.dll" "vcruntime140d.dll" to open it.

Then I found them in my computer, put them in the same dir with my application, and sent them to my friend. It worked fine, too.

But My question is "Is there any way to pack them with just Visual Studio 2019?" A small application with lots of DLLs is just a little bit weird.


回答1:


First you're sending the wrong files. Files with d suffix like that are for debugging only and must not be distributed

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

Final executable files must be compiled in release mode and use the release version of those DLLs. Don't give out debug binaries. They're seriously slow due to the logics added for debugging purposes

And you don't actually need to send the DLLs but you should tell the user to install the corresponding VC redistributable package. It's the runtime (CRT) for Visual Studio projects containing functions like printf, memcpy... for you. You don't need to find any other DLL if you don't use any DLLs in the project

It's also possible to link the runtime library statically by changing the option /MD to /MT. That way the final exe file will be self-contained (no need for additional runtime DLLs) but it'll also be larger and you lose the ability to use the newer library functions when the package is updated to fix bugs or performance issues

See also

  • Compile to a stand-alone executable (.exe) in Visual Studio
  • Compile C in Visual Studio 2012 without MSVCRT runtime
  • How to make a Single Executable VS 2010



回答2:


This is not weird, many applications put their dependencies alongside with their binary.

If you still do not want to give the DLL, you may check if the user has the required libraries installed on his computer then process a small installer which will add the missing libraries.

If you still want to "pack them", you may want to use static linking instead. Take a look at this answer.



来源:https://stackoverflow.com/questions/59234416/can-visual-studio-2019-pack-the-dlls-it-requires-in-just-a-small-exe-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!