7

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.

phuclv
  • 37,963
  • 15
  • 156
  • 475
Lau Shoo
  • 73
  • 1
  • 3
  • In my case, your comment about putting the necessary DLLs in the same folder as the app solved my immediate issue until I find a better solution. Thank you! – Alex Peters Jan 23 '20 at 02:23

1 Answers1

7

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. Again, you must compile in release mode regardless of whether you're linking statically or dynamically

See also

phuclv
  • 37,963
  • 15
  • 156
  • 475
  • Thanks for your reply! I googled the option you mentioned "/MD" and solved this problem successfully! Now my friend can open this application without installing lots of weird things! – Lau Shoo Dec 08 '19 at 12:33
  • note that your friend still needs to install the VC redist if they use other applications built with MSVC, so it's better to just install that to share between applications. And whatever option you choose, change the project to release before building the binary for distributing, don't leave it at debug – phuclv Dec 08 '19 at 12:39