views:

320

answers:

4

Why do some C++ projects require a runtime package to be installed, while others do not?

EDIT:How to make a project to work without the runtime?

+8  A: 

Some will have been statically linked, while others will depend on a dynamic library, loaded at run-time. To link your own project statically, you need to change your project configuration - how you do this depends on the compiler/linker and/or IDE you are using.

anon
How to make my program to work without the runtime installed?
John
To do this, link it statically - keep in mind this reduces forwards compatibility, and it means that you will not be able to take advantage of windows updates to the libraries, this is important if there are security related features
1800 INFORMATION
+1  A: 

I think this refers to the VS2005 service pack 1 runtime. For some reason MS added some non-backward compatible features to it, so any app built with VS2005sp1 requires the runtime to go with it.

gbjbaanb
This is true for all versions of visual studio after 2005
1800 INFORMATION
+2  A: 

Some applications are built linking with the system libraries this are the dynamic linked programs. Other programs contains the code of the libraries into the executable file this are the static linked programs.

Pros of dynamic linked:

  • Smaller size of the program executable.
  • Less memory consumption if the dynamically linked library is shared.
  • Better performance.

Cons of dynamic linked:

  • Dependency on the library.
  • Deployment is more dificult.

Pros of static linked:

  • No dependencies.
  • Easier deployment of the application.

Cons of static linked:

  • The executable file is bigger.

To get a static project you need to set up the option in the project properties.

xgoan
Dynamically linked libraries often add a level of indirection for global variables, including vtables. So I would say that they have "better performance" in some exceptional circumstances (constrained memory comes to mind.)
coryan
+1  A: 

You need to have runtime package installed in case you are working with standard C/C++ library linked as DLL, and not as static library. So one way to avoid it is to link standard C/C++ library statically (C++ project settings). It may, or may not be possible in your case.

If not, you can use dependency walker tool from Visual Studio distribution to identify the DLLs needed by your application and just put them near your executable.

What you should be aware in Visual Studio 2005 and later is that there are the manifests for binaries can (and probably will :) make your life harder. Specially since SP1 for Visual Studio 2005 changes the version of C++ library, and the manifests as well.

Cătălin Pitiș