Linking mex with Lapack
4 views (last 30 days)
Show older comments
Raunak Borker
on 16 Feb 2016
Commented: Walter Roberson
on 18 Feb 2016
Hi,
I have a small test code (mex function, 'test_lapack.cpp') that solves a linear system. To do this it calls another function written as a separate C++ file ('solve.cpp'). The C++ file calls the dgesv_ function of the lapack library. On my mac with MATLAB R2015a, I compile these as:
mex test_lapack.cpp solve.cpp -llapack
and it compiles and I can use the resulting function in MATLAB. When I do a similar thing on linux (centOS) with MATLAB R2013a:
mex test_lapack.cpp solve.cpp -lliblapack.so.3.2.1
the code still compiles. But when I call the resulting function from MATLAB, MATLAB crashes giving the following error:
INTEL MKL ERROR: parameter 2 was incorrect on entry to DGESV .
I am not sure why the Intel MKL version of lapack is being used even though I explicitly linked it to the non-intel library and the compiler is g++ (not the intel one).
I would appreciate any help in resolving this.
Thanks
0 Comments
Accepted Answer
Walter Roberson
on 17 Feb 2016
-lliblapack.so.3.2.1 is not a specific link against liblapack.so.3.2.1 . Instead, it adds liblapack.so.3.2.1 to the list of libraries to link against to resolve symbols. There is still a library order, and earlier libraries in the order may have resolved the symbol. Especially since you are using a .so instead of requesting a static library link.
You probably need to change your LD_LIBRARY_PATH; see http://stackoverflow.com/questions/2726993/g-how-to-specify-preference-of-library-path
5 Comments
Walter Roberson
on 18 Feb 2016
Does not sound quite appropriate: http://stackoverflow.com/questions/426230/what-is-the-ld-preload-trick
I would think it more likely that the approach would be closer to
old_ld = getenv('LD_LIBRARY_PATH');
setenv('LD_LIBRARY_PATH', ['/usr/lib64/liblapack.so.3:', old_ld])
More Answers (0)
See Also
Categories
Find more on Algorithm Design Basics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!