Armadillo with Visual Studio Community 2022 guide
This guide works with Windows 10 (or Server), Visual Studio Community 2022 and Intel® oneAPI Math Kernel Library version 2021.4.0.
1. Visual Studio (VS) Community 2022
Install Visual Studio Community 2022 from https://visualstudio.microsoft.com/.

You only need to choose Desktop development with C++ option.

Now your VS is ready to run.
2. Armadillo CPP library
This library is for matrix operations in CPP.
Download the most recent Armadillo CPP library (armadillo-xx.x.x.tar.xz) from http://arma.sourceforge.net/download.html.
You will need unzip program to open the file (7-zip: https://www.7-zip.org/). Unzip the file to a convenient location.
3. Intel® oneAPI Math Kernel Library (MKL)
Down load the Intel MKL library from https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl.html#gs.irg94x.

Once you downloaded, install only Intel oneAPI Math Kernel Library.

4. Create a new project with Armadillo
Create a new project in VS with “Console App” option. Choose a location and name of the project. I gave project name “ArmadilloEx”.


Then your project folder will look like this.

Copy/paste Armadillo files to your project (“armadillo-10.7.4″ folder).

Copy/paste Intel MKL files to your project (“mkl” folder).

Now, your project folder should look like this.

5. Setup VS to use Armadillo
Choose project name (“ArmadilloEx”) in the Solution Explorer window and right click –> Properties –> C/C++ –> General –> Additional Include Directories, and set as below for both Armadillo and MKL.

Choose project name (“ArmadilloEx”) in the Solution Explorer window and right click –> Properties –> Linker –> General –> Additional Library Directories, and set as below.

Choose project name (“ArmadilloEx”) in the Solution Explorer window and right click –> Properties –> Linker –> Input –> Additional Dependencies, and set (type) as below.

You are all set!
6. Run this example at ArmadilloEx.cpp.
#include <iostream> #include <armadillo> int main() { std::cout << "Hello World!\n"; // Initialize the random generator arma::arma_rng::set_seed_random(); // Create a 4x4 random matrix and print it on the screen arma::Mat<double> A = arma::randu(4, 4); std::cout << "A:\n" << A << "\n"; // Multiply A with his transpose: std::cout << "A * A.t() =\n"; std::cout << A * A.t() << "\n"; // Access/Modify rows and columns from the array: A.row(0) = A.row(1) + A.row(3); A.col(3).zeros(); std::cout << "add rows 1 and 3, store result in row 0, also fill 4th column with zeros:\n"; std::cout << "A:\n" << A << "\n"; // Create a new diagonal matrix using the main diagonal of A: arma::Mat<double>B = arma::diagmat(A); std::cout << "B:\n" << B << "\n"; // Save matrices A and B: A.save("A_mat.txt", arma::arma_ascii); B.save("B_mat.txt", arma::arma_ascii); }