Running VC++ Executable on User Machine Without its DLLs

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.

static_c_runtime_libs

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.

mfc_static_lib

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.

 

One response to “Running VC++ Executable on User Machine Without its DLLs”

  1. Hi!

    For me, linking dynamically and redistributing the used vc++ dll-files next to the “exe” works also.
    No need to install the “vcredist” on every client machine…

    BR Max

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: