#237 make fails when linking with MKL


In order to work around bug #202 ( https://sourceforge.net/p/itpp/bugs/202/ ), I tried to build IT++ 4.3.1 using the MKL v11 library provided by MATLAB.

First I exported LD_LIBRARY_PATH containing the path to mkl.so, i.e., I want to use /path/to/matlab/bin/glnxa64/mkl.so

export LD_LIBRARY_PATH=/path/to/matlab/bin/glnxa64/

Next, I run cmake as follows:

cmake -DCMAKE_INSTALL_PREFIX=/usr -DBLAS_LIBRARIES="/path/to/matlab/bin/glnxa64/mkl.so" -DLAPACK_LIBRARIES="/path/to/matlab/bin/glnxa64/mkl.so" -DFFT_LIBRARIES="/path/to/matlab/bin/glnxa64/mkl.so" ..

Next, building with make fails with the following error when linking:

Linking CXX shared library libitpp.so
/usr/bin/ld: cannot find -lmkl
collect2: error: ld returned 1 exit status

Hence, the linker seems to be unable to find mkl.so although I have exported LD_LIBRARY_PATH. Also copying mkl.so to the system's default library directory does not help (linking still fails with the same error).

Why does this procedure not work?

Is there any way using cmake to pass an -L option to the linker to provide the appropriate library directory?


  • Bogdan Cristea

    Bogdan Cristea - 2014-01-12


    There are several solutions to solve this issue:

    1) The cmake scripts used to locate external libs are located in cmake/Modules. Please have a look at these scripts in order to see which variables you need to overwrite from command line. For example when detecting LAPACK library you need to specify both:

    When using make please use
    make VERBOSE=1
    in order to see which compile options are passed to the compiler.

    2) Another solution might be to put soft links in standard locations, e.g. /usr/local/lib
    in order to ensure library detection without needing to explicitly provide library location.

    3) For detecting external libraries found in non standard locations you can use also CMAKE_INCLUDE_PATH and CMAKE_LIBRARY_PATH:

    Please let me know if this later solution works in order to update accordingly IT++ help.


  • Andreas Winkelbauer

    My bad. The file is called mkl.so and that is why the linker cannot find it. Creating a symlink called libmkl.so will do the job and IT++ will build with the configuration in my first post (exporting LD_LIBRARY_PATH is unnecessary for building).

    Later on I will update my patch for bug 202 and check if this enables me to build a single version of IT++ which will run standalone applications as well as MATLAB mex files.

  • Andreas Winkelbauer

    Since building with MKL works (applications will still crash due to bug 202), this bug can be closed IMHO.

  • Bogdan Cristea

    Bogdan Cristea - 2014-01-12
    • status: open --> wont-fix
    • assigned_to: Bogdan Cristea

Log in to post a comment.