Mex file calling LAPACK on MacOS
Show older comments
The compile of a MEX file fails on MacOS (works on Linux and Windows). The lapack function used is dpotrf and the linking step fails with:
>> Undefined symbols for architecture x86_64: >> "_dpotrf_", referenced from:
On Linux the LAPACK functions need to be referenced with an underscore added: dpotrf_, while on Windows just dpotrf worked. Should "_dpotrf_" be used on Mac?
This is code I wrote and distribute. I do not have access to a Mac. A user emailed me that he could not compile the code with:
>> mex -llapack QUIC.C QUIC-mex.C -output QUIC.mexmaci64
Compile on Windows succeeds with:
mex -llapack QUIC.C QUIC-mex.C -output QUIC.mexw64
and on Linux with:
mex -llapack QUIC.C QUIC-mex.C -output QUIC.mexa64
The Matlab Mex documents do not mention Mac support. Maybe MacOs is not officially supported?
Thanks!
Answers (1)
James Tursa
on 16 Oct 2012
Edited: James Tursa
on 17 Oct 2012
Don't add the leading underscore yourself ... the compiler will do that. For the trailing underscore you can use a macro. E.g., try putting this at the top of your code (expand to include whatever function symbols you need):
#if !defined(_WIN32) && !defined(_WIN64)
#define dpotrf dpotrf_
#endif
Alternatively, you can include the lapack.h or blas.h header file that ships with MATLAB, but that is not available for early versions of MATLAB, so the above is more robust.
2 Comments
Matyas
on 17 Oct 2012
James Tursa
on 17 Oct 2012
I don't have a Mac to test with myself, so can't answer specifically about the trailing underscore. I had assumed that it needed it. Try it both ways, and if you get the same error then it is probably not linking in the library as you suspect. One thing you can do just to get things working is copy the library to your working directory and then explicitly link it in there. That way you can at least discover exactly which name is used.
Categories
Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!