Since this question is asked on CodeProject today, I’ll answer it here.
To deploy without having to install the Visual C++ DLLs, the program has to be linked statically.
Linking to C runtime statically: Right-click on your project in the Solution Explorer and select Properties and go to C/C++ -> Code Generation. Select Multithreaded (/MT) for Release build or Multithreaded (/MTd) for Debug build.
Where are the single-threaded options? Microsoft removed them as most programs are multithreaded these days.
If your program is using MFC, do this to link to MFC runtime statically: Right-click on your project in the Solution Explorer and select Properties and go to Advanced and select Use MFC in a static library under Use of MFC.
The downside to linking statically is your executable size will be bigger but it only links the classes and functions your executable calls whereas, in the dynamical linkage case, the VC++ DLLs have to contains all the code regardless your executable calls them or not. If you package the VC++ DLLs in your installer, very likely your user has to download a larger package than one statically linked executable.
Note: C++/CLI, C++/CX and C++/Winrt programs cannot be linked statically to the C runtime. If your program links to DLLs written in the previously mentioned C++ languages, Visual C++ would not allow your program to link statically to the C runtime or MFC runtime.
When linking dynamically, then download VC++ redistributable to install on your client machine before running your program.
Leave a Reply