Matlab C++ API libMatlabEngine.so Compatibility among different Matlab Versions

13 views (last 30 days)
Hi everyone,
My question is with regards to the compatibility of the libMatlabEngine of the C++ Matlab API.
Specifically I'm building a C++ mex function with CMAKE with Matlab 2021a.
When I try to evaluate the mex function in a Matlab e.g 2023a version the libMatlabEngine.so is not found.
After running the ldd command for the mex function it seems that the mex function is still points to the libMatlabEngine.so from R2021a. All the other dynamic libraries though are successfully resolved to the R2023a though which seems a bit confusing.
I couldn't find any guidelines with explicit mention on libMatlabEngine.so compatibility among different Matlab versions and best practices on that issue. Should we build C++ mex functions specifically for only one Matlab version?
Best,

Accepted Answer

Rupesh
Rupesh on 25 Mar 2024
Hi Konstantinos,
I understand that you're facing a common challenge with MATLAB version compatibility, especially when trying to use a C++ MEX function you made in MATLAB 2021a and then running it in MATLAB 2023a. The issues is MATLAB does not guarantee binary compatibility for MEX files or applications across major releases. This absence of guaranteed compatibility means that a MEX function compiled with a specific version of MATLAB, such as MATLAB 2021a, might not function as expected—or at all—when executed in a subsequent version like MATLAB 2023a. The root of the issue often lies in changes to MATLAB's internal APIs or the binary interfaces of essential libraries, such as libMatlabEngine.so, that can vary between releases. You can refer to below documents where it is mentioned about version compatibility of mex files.
To address this issue, the first recommended solution is to compile version-specific C++ MEX functions for each MATLAB release intended for support. This approach ensures that each MEX function is linked against the appropriate version of libMatlabEngine.so and other critical MATLAB libraries.
Furthermore, careful management of environment variables, particularly on Linux systems where LD_LIBRARY_PATH plays a crucial role, is essential for ensuring that MEX functions dynamically link to the correct version of MATLAB libraries at runtime. Properly setting these environment variables to point to the specific MATLAB version's library paths can mitigate issues where a MEX function attempts to link to an incompatible version of a library like libMatlabEngine.so .
You can refer to below links for the clear understanding of libraries and version compatibility issues mentioned above.
Hope this helps!
  1 Comment
Konstantinos
Konstantinos on 25 Mar 2024
Hi Rupesh,
Thank you for your comprehensive and analytical response.
You've answered clearly the question.
Best,

Sign in to comment.

More Answers (0)

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!