Avoid using the built-in libs

2 views (last 30 days)
Juergen Wiest
Juergen Wiest on 17 Oct 2011
Hello
I've the following problem. I use a library which needs a different lapack version than the built-in matlab lapack (matlab has 3.1, I need 3.3). So I linked against the newer version which I've installed on my system and ldd showed me that the resulting .mexa64 linked correctly against it. But at runtime, the internal matlab lapack is used.
I compiled it with mex test.cpp -L<pathToMyLapack> -llapack and added the path to the LD_LIBRARY_PATH environment before starting matlab.
So my question is, how can I tell matlab to use my lapack and prevent it to use it's internal mllapack? The same problem appears with different versions of boost, std, ....
Regards
Juergen

Answers (3)

Kaustubha Govind
Kaustubha Govind on 17 Oct 2011
Note that MEX files are actually DLLs (with a slightly different extension). AFAIK, the standard behavior on Windows machines is that if the OS finds that the executable (in this case, MATLAB.exe) has already loaded the required DLL (LAPACK or other libraries), then it will attempt to use the one that is already in memory. So I guess the only alternatives are to:
  1. See if a newer version of MATLAB uses v3.3 and upgrade.
  2. Force MATLAB itself to use v3.3 (I don't know if this is possible, but you could contact MathWorks Tech Support to see what they recommend).
  3. Create an executable or some kind of out-of-process server to perform operations that call into your desired versions of libraries, and call into that from your MEX file.

Jan
Jan on 17 Oct 2011
You can load a specific DLL using LoadLibraryEx inside the Mex-function, see: MSDN:LoadLibraryEx.

Juergen Wiest
Juergen Wiest on 17 Oct 2011
@Jan Simon: I work under linux and tried to use dlopen() to load the library but it didn't work. I get the same result than using the matlab mwlapack.
@Kautstubha Govind: It works when I replace the built-in matlab lapack/blas with my lapack/blas, but I'm not sure if this is a proper solution. Maybe something else is not working anymore.
  1 Comment
Kaustubha Govind
Kaustubha Govind on 18 Oct 2011
Juergen: I'm not sure what kind of issues switching the lapack version would cause. Again, Tech Support may be able to advise better.

Sign in to comment.

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) 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!