Use Intel MKL LAPACK95 with Gfortran

Here’s how to build the Intel MKL LAPACK95 library for use with gfortran. You can also use Netlib LAPACK95 instead of Intel MKL LAPACK95.

This procedure assumes environment variable



If $MKLROOT is blank, try to find where Intel MKL is on your system (did you install Intel MKL yet?)

Build MKL and install

We install MKL (without sudo) to your project’s directory. Here we assume your project is in ~/myproject.

cd $MKLROOT/interfaces/lapack95

make libintel64 INSTALL_DIR=~/myproject/ interface=lp64 FC=gfortran

This installs to include/ and lib/ under your project directory. For repeatable builds, I like to avoid messing with system libraries. This is what Matlab and Anaconda do, that is, they put libraries under their own top-level directory.

NOTE: if you need to rebuild, delete recursively the include/ and lib/ directories under ~/myproject/, or it won’t completely rebuild.

linking to Intel MKL LAPACK95

Here are a few examples, depending on your preferred build setup.

Plain gfortran LAPACK95

Notice the extra -l in front of the name lib/intel64/libmkl_lapack95_lp64.a

gfortran mycode.f90 -o myexe -llib/intel64/libmkl_lapack95_lp64.a


Inside your Makefile, add to the end of the line where you list mycode.f90



Here I assume you’re using CMake, and assuming your main executable you’re compiling is named myexe. Add this line to CMakeLists.txt:

target_link_libraries(myexe PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/lib/intel64/libmkl_lapack95_lp64.a)

Leave a Comment