All entries for Thursday 25 March 2010

March 25, 2010

Avoiding the Visual C++ Redistributable Package

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++ compiler

This 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 executable

This 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 installer

I’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 package

For 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 executable

This 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.)

References

Deployment section on MSDN for VS2008
Visual C++ blog on the subject
Blog post covering this from a more installer-y perspective
More information about static linking issues


New blog location

After a hiatus of several years, I’ve started blogging again at blog.draknek.org.

My website

Looking for more information about Alan Hazelden? Follow me on Twitter or go to my website.

March 2010

Mo Tu We Th Fr Sa Su
Feb |  Today  | Apr
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31            

Search this blog

Blog archive

Loading…

Most recent comments

  • Knife game: No actual cutlery involved. A single player starts with the "knife" by clasping his or h… by Noyb on this entry
  • My friends and I have taken to this one very silly game lately that's probably altogether too insula… by Ian S. on this entry
  • Great, thanks for those! That first one I would know by the name of Wink Murder, usually with a sing… by Alan Hazelden on this entry
  • I don't know the names for these games, so I'll make them up: Sniper. Randomly choose who is the sin… by zep on this entry
  • I recommend checking out Project Sprouts from Luke Bayes. It makes obtaining and configuring the fla… by Duncan Beevers on this entry

Tags

Not signed in
Sign in

Powered by BlogBuilder
© MMXIV