Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does my application require Visual C++ Redistributable package

I'm writing a simple C++ application in Visual Studio. It also has a setup project. It works well on my development machine, but when I'm installing this application on user's machine it requires Visual C++ Redistributable Package. I'm wondering why does my application require C++ Redistributable? Standard C++ runtime library is shipped with Windows, isn't it?

like image 393
JeB Avatar asked Apr 23 '13 10:04

JeB


People also ask

What is Microsoft Visual C++ redistributable and do I need it?

The Visual C++ Redistributable is a DLL (Dynamic Link Library) file required by programs or games built using Microsoft's Visual Studio software development environment. When a program requires a DLL or some other supporting file to run, this is called a dependency.

Do I need to install all Microsoft Visual C++ redistributable?

These libraries are required by many applications built by using Microsoft C and C++ tools. If your app uses those libraries, a Microsoft Visual C++ Redistributable package must be installed on the target system before you install your app.

Should I uninstall Microsoft Visual C++ redistributable?

You need to uninstall and reinstall the Microsoft Visual C++ Runtime Libraries. You may need to complete this reinstallation because of: An issue during installation of F/X CAD or AutoCAD, or one of our plugins. An error message indicating a problem with the libraries.

Can I remove old Microsoft Visual C++ redistributable?

Open Control Panel: Click Start > type appwiz. cpl > hit ENTER. Uninstall all the components shown as Microsoft Visual C++ 2xxx Redistributable.


1 Answers

The only version of the C runtime library which is shipped by Microsoft with most of 32 bit Windows versions is msvcrt.dll. This library provides a typical set of library functions required by C and C++ programs. These include string manipulation, memory allocation, C-style input/output calls, etc.

Visual Studio 6.0's compiler links against this library, so if you are developing in VS 6.0 you shouldn't encounter any problems on most users' machines.

However, if you are developing in VS 2005, VS 2008, VS 2010, VS 2012, VS 2013 or VS 2015, you have to distribute additional C runtime libraries along with your application. This is because their compilers link against msvcrt80.dll, msvcrt90.dll, msvcrt100.dll, msvcrt110.dll, msvcrt120.dll and msvcrt140.dll respectively, which are not shipped with Windows.

Solutions:

  1. Possible solution is to link statically with runtime library, but it may cause a lot of problems in case you have both .exe and .dll in your application. Don't do that.

    To be more specific, I'll allow myself to quote a part of this answer:

    Using /MT is risky if you create DLLs as well as an EXE. You'll end up with multiple copies of the CRT in your program. This was especially a problem with earlier versions of VS where each CRT would get its own heap, not so much with VS2012. But you can still have ugly runtime problems when you have more than one "errno" variable for example. Using /MD is highly recommended to avoid such lossage.

  2. Another possible solution is to require an appropriate Microsoft Visual C++ Redistributable package to be installed on the user's machine.

    It may be done by specifying this requirement in prerequisites property in your setup project.

  3. Also, you can distribute the runtime dll by including in your setup project the appropriate "merge module". In this case don't forget to add the appropriate "policy merge module" to avoid errors caused by incorrect runtime version.

  4. Finally, you can just put required DLLs in the same folder in which your application is installed.

Further reading:

  • "Redistributing Visual C++ Files" - Official MSDN documentation
like image 200
JeB Avatar answered Oct 17 '22 11:10

JeB