Two of the most common used computational libraries are LAPACK and BLAS.  They are super fast in doing linear algebra operations involving matrices and vectors, .e.g. solving linear equation systems, doing SVD factorization, etc.

Originally, both packages were written in FORTRAN, but I want to use them in C++ for the purpose of basic computational research. Next, I will introduce how to install them on Linux-based systems (tested on Mac OS) for C++.

Let us create a library to adapt them to your systems.

First, you have to install BLAS before LAPACK, because LAPACK needs it. Download the packages from the following websites.

Switch to the BLAS folder and execute

make

to compile all fortran files. After that, execute

mv blas_UNIX.a libblas.a

to rename the created library. After creating the library called “libblas.a”, copy that file to your library folder by executing the following command

sudo cp libblas.a /usr/local/lib/

The above directory can be replaced by any library path in your systems.

Now we have installed the BLAS package. Then switch to the LAPACK directory and adjust the file “make.inc” if necessary. After setting all parameters correctly, type the command

make

Now, you created a library e.g. called “lapack_MACOS.a”. Copy that file to your library folder by executing

sudo cp liblapack.a /usr/local/lib/

Congratulation, you’ve installed BLAS and LAPACK on your systems!

Note: when using C++, do not forget to point out your search directory for header files with option “-I”, and add your library path with “-L” for libraries with “-l” if the search paths for the header files and libraries are not included.

Any comment or question is welcome.