What is a runtime library? I have read this and thereby I do have a decent understanding about its purpose, but is it a file? Is it something that you can include explicitly like the standard library?
-
@user0042 thanks for the input, but how does that show what a runtime library practically is? Like a physical file that you can read yourself, include, etc... – Oct 12 '17 at 10:21
-
As I stated, I _have_ read about the term. I would just love some examples of what they can be. – Oct 12 '17 at 10:23
-
A runtime library is a collection of code (functions, etc) that a user program (e.g. one you write) needs in order to work properly. For example, the C++ standard library and code executed before your `main()` function is called is usually part of a runtime library - most C++ programs can't do anything useful without it. The runtime library may be a separate executable file (e.g. a windows DLL windows that your program can't run without), or the linker may copy code directly into your executable when building so your program runs "standalone", or a combination of these. The possibilities go on – Peter Oct 12 '17 at 10:23
-
1It's the "library" part of the language *implementation*. It generally is supplied in a redistributable form with the tools for that implementation. E.g. Visual Studio has a C compiler and a C .dll (and an installer for it) – Caleth Oct 12 '17 at 10:26
-
It is a library like any other. Except that it is critical to allow your program to run and any program you write will need it. Something like strcpy() is defined in that library. Your toolset may have an option to link these functions into your final executable so you don't need the runtime libraries. – Hans Passant Oct 12 '17 at 10:50
-
@HansPassant then where is this lib stored? Can I access its content somehow? By access, I mean read/write – Oct 12 '17 at 11:03
-
It is stored where you put it. Maybe your toolset installer took care of it on your machine, they typically do. You "access" it by using a function like strcpy(). Writing to it makes no sense whatsoever, that would destroy the library. – Hans Passant Oct 12 '17 at 11:08
2 Answers
Foremost, it is concept: the code that is required to provide language features on the target platform.
i.e. it's the implementation of strlen
and feclearexcept
and ofstream::operator<<
all other standard library functions the language makes available.
It may also contain "glue code", such as making sure your ' main' gets called with the right arguments when the program starts, and other interactions with the target OS.
Like many concepts, it has different "physical" manifestations (as physical as a file can be). They depend on implementation details of the language, but commonly are:
Header files available during compilation, that contain inline implementations (e.g. the Standard Template Libary)
static libraries (.obj or .lib) files, containing already compiled functions, and included into your executable during linking.
dynamic libraries (.dll or .so) files that need to be available during execution
"special stuff the compiler or linker do" when creating your executable
A typical C++ program might see "all of the above".
The static libraries are typically created from C, C++ or assembly code that implements the standard library functions, often using fucntionality of the target OS (e.g. Windows CreateFile
for fstreams)
The dynamic libraries package (large parts of) these static libraries as a .dll or .so.
Using dynamic libraries requires the respective runtime to be installed on the target platform, but using them it reduces the size of your executable and your already-installed application benefits from updates to the runtime.
As noted, this is implementation-dependent. There might be any number of additional files (such as data files, configuration files, debug symbols, icons, etc.) associated with and included in the runtime.
Another important aspect here: the language provides an abstraction of the target platform, the abstraction layer is implemented in the runtime.

- 40,917
- 20
- 104
- 186
There are static and dynamic (runtime) libraries.
Code from static libraries are put in your executable at compile time (The Linker does this). So this code can bloat your executable but it is on every computer the same code.
When you use dynamic libraries(.dll in Windows, .so in Linux), the function is only as link stored (call XYZ() from ABC.dll). When executing your binary, the OS loads the libraries in the address space of your executable and resolves the links. So your executable is smaller and the library can be used by many programs. When there are bugs in this library, this has to replaced only once for every program. But this only works, if the interface of the library is only changed with care, otherwise - welcome to DLL hell.

- 52,200
- 2
- 44
- 75

- 537
- 4
- 16