#237 make fails when linking with MKL

release_4.3.x
wont-fix
None
1
2014-01-12
2014-01-12
No

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?

Discussion

  • Bogdan Cristea
    Bogdan Cristea
    2014-01-12

    Hi

    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:
    BLAS_LINKER_FLAGS and BLAS_LIBRARIES

    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:
    http://itpp.sourceforge.net/4.3.1/installation.html#localinst_cmake

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

    regards
    Bogdan

     
  • 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.

     
  • 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