Use external BLAS and LAPACK libraries in a MATLAB mex file

梦想与她 提交于 2019-12-11 04:25:59

问题


I am currently try to build an interface for a numerical software library to MATLAB. Thereby I end up with the following problem:

MATLAB uses per default 64 bit integers and its BLAS and LAPACK library (namely the MKL) supports only 64 bit integers as well. Unfortunately the library which I want to connect via a mex-file to Matlab uses only 32bit integers and its dependencies too. Whenever the mex-file now tries to call a function from BLAS or LAPACK it crashes because of the different integer widths.

I try to link my mex-file against my own BLAS and LAPACK versions with 32bit integers using

mex  myinterface.c -largeArrayDims -llapack -lblas

The linker includes the reference to both libraries in the mex file, but if I call it now from MATLAB it crashes. From the backtrace I got that one LAPACK call produces a segementation fault which seems to be cause by the different Integer widths. Furthermore the backtrace tells me that the MKL caused this error instead of the BLAS and LAPACK I linked to my program.

The question is: Is there a possibility to link the mex file to its dependencies such that it resolves the symbols from it instead of the ones from MATLAB, i.e. uses the given BLAS and LAPACK libraries?

remarks:

  • MATLAB 2013
  • GCC 4.6
  • BLAS and LAPACK libraries are dynamical.

回答1:


I know this question is a year old already, but this might be useful for somebody:

I believe your problem would be solved if you pre-loaded dynamically linked libraries to enforce their use (maybe along with changing your LD_LIBRARY_PATH as Shai has suggested). I had to do something similar to enforce use of particular versions of some libraries. LD_LIBRARY_PATH works for external libraries (such as OpenCV), while LD_PRELOAD for standard libraries. On your command line, type the following:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/OpenCV/lib/:/path/to/SomethingElse/lib
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.16:/path/to/libOtherStandardLibrary.so
matlab

This helps also with the problem of stdc++ having different version for the system and for Matlab (which carries its own, older, version).



来源:https://stackoverflow.com/questions/20544265/use-external-blas-and-lapack-libraries-in-a-matlab-mex-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!