Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to Install Boost Library in C++ on Linux?

  • Last Updated : 16 Oct, 2021

Boost is a set of libraries for the C++ programming language. It contains 164 individual libraries. It was initially released on September 1, 1999. Furthermore, it provides support for many tasks such as pseudo-random number generation, linear algebra, multithreading, image processing, regular expressions, and unit testing. In this article, we are going to learn how we can install a boost library in C++ on Linux.

Installing Boost Library in C++ on Linux:

Method 1: Using apt-get command:

To install the boost library on your Linux, run the following command in your Linux terminal.

sudo apt-get install libboost-all-dev
Installing Boost Library in C++ on Linux using apt-get command

installing the boost library

Confirm the installation by pressing y from the keyword. This will confirm that the user wants to install the above-listed packages.

To verify the installation, let’s run a sample program using the boost library.

In this sample program, we are going to create an array using the boost library. For that, we have to include the boost’s array header file into our CPP program.

Code:

C++




#include <boost/array.hpp>
#include <iostream>
  
using namespace std;
int main()
{
    boost::array<int, 10> arr
        = { { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } };
    for (int i = 0; i < 10; i++) {
        cout << "Geek Rank is :" << arr[i] << "*"
             << "\n";
    }
    return 0;
}
Output
Geek Rank is :1*
Geek Rank is :2*
Geek Rank is :3*
Geek Rank is :4*
Geek Rank is :5*
Geek Rank is :6*
Geek Rank is :7*
Geek Rank is :8*
Geek Rank is :9*
Geek Rank is :10*
My Personal Notes arrow_drop_up
Recommended Articles
Page :