How to Install and use a C++ Standard Library
A library can be defined as a package of code or functions that is used in various applications. By having libraries, we achieve reusability. It’s one of the principles of Object-Oriented Programming.
In this article, let’s find out two types of C++ libraries and help you with installation and usage of a C++ Standard Library.
Two types of C++ Libraries
A C++ library usually consists of:
-
-
-
- A header file: This defines the functionality that the library is offering.
- A precompiled binary: This file contains the actual implementation of the functionality. This implementation is precompiled into a machine language.
-
-
Libraries are precompiled as they hardly change. Secondly, as the precompiled libraries are into a machine language form, they are secured and nobody can access them directly.
In C++ we have two types of Libraries:
-
-
-
- Static Libraries
- Dynamic libraries
-
-
Static Libraries
Static Libraries are also called as Archives. A static library is a library that becomes a part of the executable which references it. Thus when we develop an application and reference a static library in it, the contents of the static library are replaced in the application.
The static libraries on Windows usually have an extension “.lib” while those on Linux has extension “.a” (or archive).
One advantage of static library is that we don’t have to distribute the static library along with the executable, because the contents of the static library are a part of the applications.
The disadvantage of having static library is that the executable can become bulky and too much space is wasted as the library is a part of the executable.
Another disadvantage is that if the static library changes, then the executable referencing it needs to be updated as well.
Dynamic Libraries
The dynamic library is a library that consists of routines that are loaded into the application at run time. When an application references a dynamic library, then the library does not become a part of the application but it remains as a separate unit. Because many application can use one dynamic library so it’s also known as “shared library“.
In Windows, the dynamic library has the extension “.dll” (dynamically linked library). On Linux, it has the extension “.so” (shared object).
The dynamic library has an advantage that one copy of the library can be shared by many applications thereby saving space. Yet another advantage is that, as the dynamic library is a separate unit, the application executable does not change when the dynamic library changes.
The only disadvantage that a dynamic library has is that it requires a separate program to load and reference the library which can be cumbersome.
How To Install And Use C++ Libraries
Let’s see some of the steps that we need to follow to install these libraries and use to install and use C ++ in our application.
1. Acquiring the Library
In order to use the library in our application, we first need to acquire the library. The library may be precompiled – in such a case we just need to download the library for the operating system. If the library is not precompiled, then we need to download the source code and compile it on our machine.
On windows, the libraries usually have .zip extension while on the Linux Operating system the library package is distributed as ‘.RPM’.
2. Install the Library
The next step once we obtain the library is to install the library. Installation on Windows is as simple as unzipping the contents of the library in a folder. On Linux, we can invoke the package manager to install the library.
3. Include the Library path for the Compiler
We need to set the path of the library so that the compiler knows where to look for the library files. This can be ‘include’ directory on Windows or ‘/usr/include’ on Linux.
4. Link the Library path
This step is performed so that the linker knows the exact path of the libraries that it has to link during the linking process. Usually, there is ‘/lib’ folder on Windows or ‘/usr/lib’ folder on Linux that contains all the libraries.
Once the library is installed, the compiler and the linker know the path of the library to use, and the library is ready for use.
Conclusion
We discussed C++ libraries in detail along with their types, and the steps to install and setup the library. Hope that it will help you to apply to do it yourself.
iRender is currently providing GPU Cloud for AI/DL service so that users can train their models. With our high configuration and performance machines (RTX3090), you can install any software you need for your demands. Just a few clicks, you are able to get access to our machine and take full control of it. Your model training will speed up times faster.
Moreover, we provide other features like NVLink if you need more VRAM, Gpuhub Sync to transfer and sync files faster, Fixed Rental feature to save credits from 10-20% compared to hourly rental (10% for daily rental, 20% for weekly and monthly rental).
You can register an account today to experience our service. Or contact us via WhatsApp: (+84) 916806116 for advice and support.
Thank you & Happy Training!
Source: softwaretestinghelp.com
Related Posts
The latest creative news from Cloud Computing for AI,