Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If C++ compiles to machine code, why do we need to install a 'runtime'?

At the end of the compilation process, the program is in a .exe file in machine code. So shouldn't the machine be able to run it without having to install something like MS Visual Studio C++? Basically, I am making a program with mingw and want to share it with someone else. I do not understand why I can not just send them the .exe file. Clarification will be appreciated.

like image 952
ICanKindOfCode Avatar asked Dec 03 '22 20:12

ICanKindOfCode


1 Answers

C++ compiles your code to machine code. If your program is self-contained, that is all you need. However, more complex running programs often relies on additional compiled code, which is made available to your program through a library.

Generally, libraries come in two "flavors" - static and dynamic. Static libraries are "baked into" your compiled code. This is not ideal, because multiple programs include identical code, leading to code duplication. Dynamic libraries, on the other hand, are shared among all programs using them, leading to more efficient use of space.

Installing runtime adds dynamic libraries for use by all programs compiled with C++.

like image 92
Sergey Kalinichenko Avatar answered Dec 11 '22 12:12

Sergey Kalinichenko