I made a
blog post about distributing applications built in Visual Studio; copied here:
Visual Studio is a great IDE. Unfortunately the C++ compiler is horrible. Among other things, under the default settings a compiled application won't actually run out of the box on a large number of computers.
This is because of the "Visual C++ Redistributable Package" which must be installed to run applications compiled from Visual Studio. This behaviour is nonsensical to me, but nevertheless it is there and must be worked around.
There are the solutions that I know of:
Don't use the Visual C++ compilerThis is my solution, but then I do my development from Linux anyway.
MinGW is an implementation of the GCC compiler suite for Windows, and creates executables that don't rely on invisible Microsoft dependencies.
It may or may not be possible to use an alternative compiler from within the Visual Studio IDE. I can't find any references for it, but I have heard (though not tested) that it is possible to set up a project that uses a makefile to build.
Code::Blocks is probably the best alternative IDE to Visual Studio. They also provide a download package which includes MinGW.
Include DLLs with executableThis is what Microsoft calls a "private assembly" and what I call "putting the DLLs in the application directory".
The files you need will be in
C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\ (or equivalent) on a computer with Visual Studio installed. As well as the three DLL files
msvcm90.dll,
msvcp90.dll and
msvcr90.dll, you will also need the manifest file
Microsoft.VC90.CRT.manifest.
Copy these files to the directory containing your executable and include them with your download.
Use an installerI've not done this myself, and for a lot of the people I expect to read this, it will be overkill. So not much useful advice to give here, other than to read
this blog post to see the options. Does anyone have a "how to create a ridiculously simple installer" guide?
Get end users to install the Visual C++ redistributable packageFor Visual Studio 2008 SP1 this is downloadable
here: other versions are similarly available from the same site.
Once installed, your application will run on that computer, but obviously this is not very convenient for the user.
Statically link the Visual C++ libraries into your executableThis is potentially problematic if you are using other libraries: all the DLLs you are using must have been compiled under the same settings. For example, the precompiled builds of SDL for Visual Studio are apparently incompatible with this. So you may have to get your hands a bit dirty to get it to work (or you may not). To do this, go to:
Project -> Properties -> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library -> change to "Multi-threaded [Debug]" instead of "Multi-threaded [Debug] DLL"
You need to change this in both debug mode and release mode.
Microsoft strongly recommends you not do this, as security issues cannot be patched if the library code is statically linked into your executable. (Sidenote: interestingly, putting the DLLs in the application directory doesn't have this problem, because if you have a more recent version installed that will be used instead.)
ReferencesDeployment section on MSDN for VS2008Visual C++ blog on the subjectBlog post covering this from a more installer-y perspectiveMore information about static linking issues