The pkg-config tool[1] is a widely used tool that many users apply to their makefiles. Intel® Math Kernel Library (Intel® MKL) provides pkg-config metadata files for this tool starting with the Intel MKL 2018 Update 1 release.
The Intel MKL pkg-config metadata files cover only the most popular Intel MKL configuration on 64-bit Linux/macOS/Windows operating systems for C.
This table describes the Intel MKL pkg-config metadata files provided and the Intel MKL configurations that they cover.
pkg-config is a helper tool that provide the necessary options for compiling and linking an application to a library. For example, if you want to build your source code test.c with Intel MKL, you can call the pkg-config tool and provide the name of the Intel MKL pkg-config metadata as an input parameter. The full compiling and linking line would be:
Linux OS: icc test.c `pkg-config --cflags --libs mkl-dynamic-lp64-iomp`
Windows OS: for /F "delims=," %i in ('pkg-config --cflags --libs mkl-dynamic-lp64-iomp') do icl test.c %i
For the mkl-dynamic-lp64-iomp Intel MKL configuration (dynamic linking, LP64 interface and Intel® OpenMP threading library) the pkg-config tool generates the following full executable command line on Linux OS:
icc test.c -I/opt/intel/compilers_and_libraries/linux/mkl/include -L/opt/intel/compilers_and_libraries/linux/mkl/lib/intel64_lin -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -L/opt/intel/compilers_and_libraries/linux/mkl/../compiler/lib/intel64_lin -liomp5 -lpthread -lm -ldl
To get the compilation line for Intel MKL, call pkg-config with the --cflags option:
pkg-config --cflags mkl-dynamic-lp64-iomp
To get the link line for Intel MKL, call pkg-config with the --libs option:
pkg-config --libs mkl-dynamic-lp64-iomp
The pkg-config tool helps avoid large hard-coded link lines inside makefiles and makes it easy to change the linking line by using another pkg-config metadata file as an input parameter for the pkg-config tool or by adjusting the metadata file itself.
To adjust compilation and link options in the pkg-config metadata file:
- Go to the <mkl_install_dir>/mkl/bin/pkgconfig directory.
- Specify the ${prefix} variable, which contains the full path to the Intel MKL directory that could be changed if another path to MKL is needed.
- Specify Libs:the link line that is returned by pkg_config --libs. You can get the preferred link line for the Intel MKL configuration using the Intel MKL Link Line Advisor or the offline Intel MKL link line tool. In the link line returned by the advisor, be sure that you change the external environment variable ${MKLROOT} to the internal pkg-config ${prefix}, since the pkg-config metadata file will not work with the external environment variable. However you can set it outside with the pkg-config tool (see the pkg-config tool man page for more information).
- Specify Cflags: the compiler options that will be returned by pkg-config --cflags. You can also update it (see the instruction from step 3).
Example of Intel MKL pkg-config metadata file mkl-dynamic-lp64-iomp for Linux OS:
prefix=/opt/intel/compilers_and_libraries/linux/mkl
exec_prefix=${prefix}
libdir=${exec_prefix}/lib/intel64_lin
omplibdir=${exec_prefix}/../compiler/lib/intel64_lin
includedir=${prefix}/include
#info
Name: mkl
Description: Intel(R) Math Kernel Library
Version: 2018 Update 1
URL: https://software.intel.com/en-us/mkl
#Link line
Libs: -L${libdir} -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -L${omplibdir} -liomp5 -lpthread -lm -ldl
#Compiler line
Cflags: -I${includedir}
To use Intel MKL pkg-config metadata files with the pkg-config tool please be sure that you add the full path for the Intel MKL pkg-config metadata files to PKG_CONFIG_PATH so that pkg-config can locate them.
Use the Intel MKL environment script to set up entire Intel MKL environment.