Out of process MEX for C

3 次查看(过去 30 天)
Leo McCormack
Leo McCormack 2020-10-19
Hi!
Context:
I am a researcher with a lot of existing C code, and I have recently written a few C-MEX wrappers to try and bring this existing code functionality into Matlab.
I make several references to cblas+lapack functions in my own C code, which in turn, is inhereted by these C-MEX wrappers. I therefore link either: a custom Intel MKL library (lp64 interface), Apple Accelerate, or OpenBLAS+netlib LAPACK, when building the mex objects (depending on the OS and what I have to hand etc.).
Since all of these cblas+lapack supporting libraries conform to a standard, the code's operation is equivalent across all of these different options/platforms (...given some numerical error as their implementations will vary etc. but this often not an issue in practice).
Problem:
The C-MEX objects seem to alway link to Matlab's own Custom Intel MKL library (ILP64 interface), even if no cblas/lapack function calls are made within the C-MEX code itself. Therefore, at run-time, I have the situation where there are 2 libraries with identical cblas+lapack symbols being linked to the C-MEX object. If I am lucky, it resolves this symbol linking by finding the cblas+lapack supporting library that I explicitly linked with the C-MEX object. However, if I am unlucky, then it will link with Matlab's ILP64 interface MKL library, and lead to crashes, since the ILP64 interface is a specialised "off-standard" variant not supported by any of these other libraries (basically, using int64 instead of int32).
Solution(s)?:
From what I understand, running the C-MEX object "out-of-process", like how the C++MEX object can be used, will likely solve this issue. However, this feature has not yet been brought to the C-MEX API; and it is unclear whether it ever will be.
Therefore, is there a way to explicitly tell the matlab compiler to not link C-MEX objects against Matlab's cblas+lapack library? - I don't use or need it...
Failing that, is there a simple way to wrap around an existing C-MEX API written mexFunction, with the C++ MEX wrapper?
Any help or suggestions would be much appreciated : )
Many thanks and best regards,
Leo

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Write C++ Functions Callable from MATLAB (MEX Files) 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by