# How to install Armadillo library in Ubuntu

Armadillo is a high-quality linear algebra library for the C++ language. The good thing is that it follows similar syntax with MATLAB. It provides classes for vectors, matrices and cubes. It is easy to install. There are three ways to do it:

First, we need to install the dependencies since various matrix decompositions are provided through integration with LAPACK, or one of its high-performance drop-in replacements

sudo apt install libopenblas-dev liblapack-dev

in official documentation, it also recommends installing CMake, libarpack2-dev, libsuperlu-dev

b. Install from source

If we want the most recent version, for example, Ubuntu18 provides 8.4 and the current version is 9.8, we need to build it from the source. We need to download it from the official repository and most likely do the followings

tar -xvf armadillo-9.880.1.tar.gz
./configure
make
sudo make install

c. Install from source

This is an alternative to b where we use checkinstall install of make install. The reason is mainly to avoid a cluttered /usr/local folder. It is advised first to understand how the utility works (check references) and then apply it in our case.

Now when it comes to using with CMake for example, just use

cmake_minimum_required(VERSION 3.16)
project(arma)

set(CMAKE_CXX_STANDARD 17)

target_link_libraries(arma_test armadillo)

with a sample file like:

#include <armadillo>
#include <iostream>

using namespace arma;
using namespace std;

int main() {

mat A(2, 3);// directly specify the matrix size (elements are uninitialised)
A << 1 << 2 << 3 << 3 << endr
<< 2 << 0 << 6 << 2 << endr
<< 3 << 4 << 9 << 7 << endr;

A.print("A:");
mat B = orth(A);
B.print("B:");

cout << "The rank of A is " &lt;&lt; arma::rank(A) << endl;
return 0;
}