Thread: What is a Runtime Library in C/C++

  1. #1
    Thang Le thavali's Avatar
    Join Date
    Jan 2011
    Location
    Earth
    Posts
    20

    What is a Runtime Library in C/C++

    hi all,
    After read about Runtime Library at:
    Difference between C/C++ Runtime Library and C/C++ Standard Library. - Stack Overflow

    finally, I have not still understand : What is a Runtime Library ?, why printf, fopen,... is a part of Runtime Library ?
    Please explain more detail about C/C++ Runtime Library , add examples is great.

    Runtime library is different to Dynamic library ?

    Thanks ,
    thavali

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Quote Originally Posted by thavali View Post
    hi all,
    After read about Runtime Library at:
    Difference between C/C++ Runtime Library and C/C++ Standard Library. - Stack Overflow

    finally, I have not still understand : What is a Runtime Library ?, why printf, fopen,... is a part of Runtime Library ?
    Please explain more detail about C/C++ Runtime Library , add examples is great.
    I read the same page you did, and my conclusion is that the examples you gave: printf and fopen; are part of the standard library.

    Runtime library is different to Dynamic library ?
    If the source you linked is to be believed, then there is no difference between those things at all. A run time library is what it says on the tin. It's not the most descriptive term, as your source already told you. A library is loosely defined as a collection of code, and by the phrase "run time" we extrapolate that the library works when it is executed, as opposed to some other time. How many ways can you look at something distinctive and call it a "collection of code"? They're all equally valid.

  3. #3
    Password:
    Join Date
    Dec 2009
    Location
    NC
    Posts
    587
    Given whiteflags very good, but maybe overcomplicated response, I see the need to answer with a simple: no, they are not different. They are for the same thing, and do the same thing.

  4. #4
    Thang Le thavali's Avatar
    Join Date
    Jan 2011
    Location
    Earth
    Posts
    20
    Thanks whiteflags and User name.

    Quote Originally Posted by User Name: View Post
    Given whiteflags very good, but maybe overcomplicated response, I see the need to answer with a simple: no, they are not different. They are for the same thing, and do the same thing.
    as i known, the dynamic library is which libraries will be loaded dynamically when program is running. In linux, it's file with .so extension. In opposite, static library is which libraries was loaded in compile-time. In linux, it's file with .a extension. Because functions as printf and fopen were defined in static library. So, i don't think Runtime library and Dynamic Library is same.
    Here, we are talking in Linux environment.

    Regards

  5. #5
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    You don't have to link the standard library with your executable. I'm positive it has both .a and DLL versions.

    The reason you do this with any library is to get smaller executeables.

  6. #6
    Thang Le thavali's Avatar
    Join Date
    Jan 2011
    Location
    Earth
    Posts
    20
    because i work in embedded system. So, printf or fopen is functions built-in in a static prebuilt library (.a extension). So, my executeable file included the .a libraries.

  7. #7
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Quote Originally Posted by thavali View Post
    because i work in embedded system. So, printf or fopen is functions built-in in a static prebuilt library (.a extension). So, my executeable file included the .a libraries.
    OK, I'm not getting through for some reason:

    There is a document called the standard, which outlines what you need to do to write a C or C++ compiler. The standard library is a part of that document. The meaning of the term standard ends here.

    This sentence
    In opposite, static library is which libraries was loaded in compile-time. In linux, it's file with .a extension. Because functions as printf and fopen were defined in static library.
    literally just means that the standard library can be linked statically. The standard library itself could be a run time library but you aren't using it that way. That's all. libc.so exists, that is all I'm saying.

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by whiteflags View Post
    You don't have to link the standard library with your executable. I'm positive it has both .a and DLL versions.
    Under unix, a DLL often has a .so extension.

    In any event, the .a archives are sometimes referred to as "link libraries" and .so files are sometimes referred to as runtime libraries.

    Under windows, a LIB file would be referred to as a link library, and a DLL as a runtime library.

    The distinction is that contents of a link library would be bundled in the executable for an application, so the library would not need to be distributed with the executable as a separate file. A runtime library would need to be distributed with the application, otherwise the application would not be able to run.

    Any function in the C standard library may be bundled either in a runtime library or a link library. The decision is one of packaging by the vendor of the compiler and library. Often developers of applications have options (eg IDE settings, command line options) to select whether the C runtime library is linked statically (against the link library) or not into any application. The tradeoff is one of executable size versus need to ship separate files for the executable to run.
    Last edited by grumpy; 04-11-2011 at 04:09 AM.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  9. #9
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    Maybe the original poster is just confused because so many standard library implementations, static and shared library variants, call the library the "C Run-time Library". (I'm looking at you Microsoft.)

    Soma

  10. #10
    Thang Le thavali's Avatar
    Join Date
    Jan 2011
    Location
    Earth
    Posts
    20
    Quote Originally Posted by grumpy View Post
    Often developers of applications have options (eg IDE settings, command line options) to select whether the C runtime library is linked statically (against the link library) or not into any application.
    Thanks grumpy,

    This is mean that if you have a runtime library with .so extension, you can use this runtime library for a static link ?
    As i known, the way to call a function in the static library and in the shared library is different.

    ============
    This is define about runtime library from compiler guide that i am using (IAR for ARM compiler)

    Introduction to the runtime environment:
    The runtime environment is the environment in which your application executes. The runtime environment depends on the target hardware, the software environment, and the application code.
    RUNTIME ENVIRONMENT FUNCTIONALITY
    The runtime environment supports Standard C and C++, including the standard template
    library. The runtime environment consists of the runtime library, which contains the
    functions defined by the C and the C++ standards, and include files that define the
    library interface (the system header files).
    The runtime library is delivered both as prebuilt libraries and (depending on your
    product package) as source files, and you can find them in the product subdirectories
    arm\lib and arm\src\lib, respectively.
    The runtime environment also consists of a part with specific support for the target
    system, which includes:
    ● Support for hardware features:
    ● Direct access to low-level processor operations by means of intrinsic functions,
    such as functions for interrupt mask handling
    ● Peripheral unit registers and interrupt definitions in include files
    ● The Vector Floating Point (VFP) coprocessor.
    ● Runtime environment support, that is, startup and exit code and low-level interface
    to some library functions.
    ● A floating-point environment (fenv) that contains floating-point arithmetics support,
    see Floating-point environment, page 268.
    ● Special compiler support, for instance functions for switch handling or integer
    arithmetics.
    ===================

    I go into the above folders and see that: all libraries in arm\lib folder are .a extension. and in arm\src\lib folder are .c or cpp extension.

    Code:
    The runtime environment consists of the runtime library, which contains the
    functions defined by the C and the C++ standards, and include files that define the
    library interface (the system header files).
    So, runtime libraries can be either a static libraries or a shared libraries ?


    Thanks
    Last edited by thavali; 04-11-2011 at 05:43 AM. Reason: add more question

  11. #11
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    As i known, the way to call a function in the static library and in the shared library is different.
    You, as a C++ programmer, don't have to change anything to use facilities a shared library. Rather, if you do have to, something is horribly broken somewhere.

    There are different calling conventions, but if you are only using a library, it should be none of your concern.

    Soma

  12. #12
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by thavali View Post
    This is mean that if you have a runtime library with .so extension, you can use this runtime library for a static link ?
    Generally, no. If the library is distributed as a .a file (and archive containing a set of compiled objects: i.e. a static library), that .a file can be used in a static link.

    A runtime library (.so) remains a separate file (which can be used by multiple applications, and found while the operating system loads the application executable) and is therefore not used in a static link.

    Quote Originally Posted by thavali View Post
    As i known, the way to call a function in the static library and in the shared library is different.
    That is not true.

    Generally, from a coding perspective, the technique to call a function is the same, whether the function comes from a separate object file (.o), a static library, or a shared library.

    What differs is how the application is linked (i.e. how the linker creates the executable for the application). That is consistent with the fact that static libraries and shared libraries are created using different techniques, and have somewhat different (albeit related) file formats, even if they are each created from the same source code.

    As soma mentioned there are matters of calling conventions. But as long as the application sticks to the calling convention that functions in a library expect to be called by, there is no problem. That doesn't change for functions in different types of libraries.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  13. #13
    Thang Le thavali's Avatar
    Join Date
    Jan 2011
    Location
    Earth
    Posts
    20
    Very thanks all everybody.

    may be, IAR (iar.com) was wrong in naming their library. because if they packaged and shipped the libraries in static libraries (.a extension), then they should not name us is Runtime library.

  14. #14
    Thang Le thavali's Avatar
    Join Date
    Jan 2011
    Location
    Earth
    Posts
    20
    after read from Wiki : Runtime library - Wikipedia, the free encyclopedia

    looking at the section:
    The concept of a runtime library should not be confused with an ordinary program library like that created by an application programmer or delivered by a third party or a dynamic library, meaning a program library linked at run time. For example, the programming language C requires only a very minimal runtime library, but defines a large standard library (called C standard library) that each implementation has to deliver.
    In my opinion. A Runtime library is the libraries with the feature follow:

    - Runtime library consists a collection of functions specialize in a specific target hardware.
    For example: behavior of printf function in each different target hardware is different. In x86 PC platform , printf will out a string to console, but in embedded ARM board, may be printf will out a string to serial port. so printf is apart of runtime library.
    - Runtime library consists a collection of functions which is only used by compiler, application developer cannot to use it.
    For example: in compiling processing, compiler creates some internal functions automatically. These functions are used for some tasks as initialize zero data (__int_zero_data__), __main(),..
    These functions cannot call by application developer.
    - Runtime library consists functions that can be performed only (or are more efficient or accurate) at runtime are implemented in the runtime library.
    For example: some logic errors, array bounds checking, dynamic type checking,...

    Sometime, the C standard library can be included to runtime libarary, too. This is up to compiler manufacturer.

    So, i conclusion that In Linux environment, the Runtime library is different with the dynamic library.

    Addition, Below is a define about Runtime library from book: GCC The Complete Reference - Arthur Griffith -© McGraw-Hill 2002 ( page 614)

    runtime
    Also called the runtime package, the runtime is a collection of functions that are
    distributed with the compiler and linked to the compiled programs because they are
    called when the application is running.
    Please comment
    Regards
    Thavali

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stuio 2008 Changes to runtime library
    By Mario F. in forum C++ Programming
    Replies: 1
    Last Post: 08-03-2009, 07:33 AM
  2. Runtime formation and execution at runtime
    By Soham in forum C Programming
    Replies: 17
    Last Post: 08-27-2008, 08:45 AM
  3. link with C runtime library
    By George2 in forum C++ Programming
    Replies: 26
    Last Post: 02-05-2008, 01:56 AM
  4. runtime library option
    By George2 in forum C Programming
    Replies: 1
    Last Post: 11-30-2007, 08:45 AM
  5. A runtime library error on this line???
    By Unimatrix_001 in forum C++ Programming
    Replies: 2
    Last Post: 09-04-2003, 03:42 PM