Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 575
Lau Shoo Avatar asked Dec 08 '19 10:12

Lau Shoo


People also ask

How do I create a DLL project in Visual Studio 2019?

To create a DLL project in Visual Studio 2019On the menu bar, choose File > New > Project to open the Create a New Project dialog box. At the top of the dialog, set Language to C++, set Platform to Windows, and set Project type to Library.

Can C# be compiled to exe?

After a developer writes the C# code, he or she compiles their code. This results in Common Intermediate Language stored within Portable Executable (PE for 32-bit, PE+ for 64-bit) files such as “.exe” and “. dll” files for Windows. These files are distributed to users.


1 Answers

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

  • 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
like image 105
phuclv Avatar answered Oct 05 '22 10:10

phuclv