Alex Rivera | Logout

Microsoft Visual Studio ~ C/C++ Runtime Library ~ Static/dynamic linking

Asked 2013-02-07T11:08:32.507
50

I am a Microsoft Visual Studio user. My question is about the "C/C++ Runtime Library".

I created an "Empty Project" with a ".cpp" source file "main.cpp" containing the following code:

#include <iostream>

int main(void)
{
    std::cout << "Hello World" << std::endl;
    return 0;
}

"iostream is a header file which is used for input/output in the C++ programming language. It is part of the C++ standard library."

  1. Is there a difference between "C/C++ Runtime Library" and "C/C++ Standard Library"?

  2. How do I know if the "C/C++ Runtime Library" library is statically or dynamically linked to the project?

  3. How do I know where this library is located in the filesystem?

  4. In case, the "C/C++ Runtime Library" is dynamically linked to the project, how can I know which ".dll" is used and where the used ".dll" is located in the filesystem?

  5. Suppose that I statically link the "C/C++ Runtime Library" to the project, can I be sure that the executable generated from the source code will work on all Windows Platforms (XP/Vista/Seven/..., 32 bit/64 bit)?

  6. What are the advantages/drawbacks of dynamically linking the "C/C++ Runtime Library" to the project?

  7. Should the "C/C++ Runtime Library" rather be statically or dynamically linked to the project?

Edit
Report

1 Answer

66

The term "C/C++ Runtime Library" doesn't mean anything, it is roughly the name of a project setting in the IDE. Project + Properties, C/C++, Code Generation, Runtime Library setting. There you can choose between /MD and /MT.

With /MD, the default setting, your program will be using the DLL version of the runtime libraries. On your machine they were copied into c:\windows\system32 and/or c:\windows\syswow64 by the Visual Studio installer. And you've got copies of them in the vc/redist subdirectory of the VS install directory, there for you to use when you create an installer for your program. Three versions of them, x86 for 32-bit Intel processors, x64 for 64-bit Intel processors and arm for ARM processors. Pick the right one based on the Platform you selected in your project.

The relevant DLL names are:

  • msvcr110.dll : the C runtime library (memcpy et al)
  • msvcp110.dll : the C++ standard library (std::string et al)
  • vccorlib110.dll : the runtime library for Windows Store applications
  • vcomp110.dll : the runtime library for OpenMP (see #pragma omp)
  • atl110.dll : the runtime library for ATL projects
  • mfc110*.dll : runtime and localization libraries for MFC projects
  • vcamp110.dll : the runtime library for AMP projects

On your machine, you've also got the debug builds of those DLLs, copied to the Windows directory by the VS installer. They have the same name with the letter "d" appended. Useful only to debug your code, you can't redistribute them. The corresponding Runtime Library setting is /MDd.

Most C++ projects only need msvcr110.dll and msvcp110.dll, you'd know when you opt in to use the other libraries since there are specific project templates and settings for them.

A simple way to get all of these DLLs installed on your user's machine is to use the prebuilt installer. You can download it answered 2013-02-07T13:33:33.930

Your Answer