In programming, a library is a collection of precompiled routines that a program can use. The routines, sometimes called modules, are stored in object format. There are different types of libraries in C++ and the main purpose of all the libraries are same which is to add your own choice, which type of program you want. For example, if you want to create your program with cin and cout statements you will add #include<iostream> library in your library and the library of io stream will be added. Just like if you want to develop string related programs you will add #include<string> in your program and the library of strings will be added. Libraries are particularly useful for storing frequently used routines because you do not need to explicitly link them to every program that uses them. The linker automatically looks in libraries for routines that it does not find elsewhere.
How Libraries Are Precompiled?
Libraries are precompiled for several reasons. First, since libraries rarely change, they do not need to be recompiled often. It would be a waste of time to recompile the library every time you wrote a program that used them. Second, because precompiled objects are in machine language, it prevents people from accessing or changing the source code, which is important to businesses or people who don’t want to make their source code available for intellectual property reasons.
How Libraries Are Added In Program?
“#include” the library’s header file in your program. This tells the compiler about all of the functionality the library is offering so that your program will compile properly.
When you type #include in your program means that you are going to add a library in your program. And then you type “< >” sign to add the header file.
With most compilers on most UNIX systems, the C++ runtime library is a shared library. Most of the C++ standard library is implemented only in C++ header files which require no library at all.
DIFFERENT TYPES OF LIBRARIES
Some main libraries are:
- Runtime library
- Debug library
- Development library
These libraries are elaborated below:
Runtime library: The shared library necessary to run applications that are dependent on this library.
Debug Library: A runtime library compiled with debugging information (-g) which can be potentially useful for tracking down library related bugs.\
Development Library: Typically this is a package containing header files and static libraries needed to compile applications to use the library. This is only needed by developers, not regular users of the library. This package may also include developer documentation.
SOME MAIN LIBRARIES ARE
For me, I include all the libraries in C++ so if I need any function I would use it without remembering in what library it was.
This article is written by Ghias Hassan. He is a tech geek. He loves to write about computer & technology. He works as a professional writer at C++ Beginner Blog.