Will Matlab ever permit C++ DLL's?

27 views (last 30 days)
Kristoffer Walker
Kristoffer Walker on 23 Feb 2016
Answered: Vivek on 2 Oct 2019
Folks,
I have C++ specific functions (I use a lot of templates and overloading) that I would like to be able to use on a continuous basis from Matlab. However, these things cannot be "extern C'd" to use them with loadlibrary. I really am not a fan of having to create a special interface using Mex, because I want to use the same API for all Applications that call my library DLL's (efficient this way, and permits using Matlab to test the library functions using the same API).
Will Matlab in the future ever permit using loadlibrary with true C++ DLL's without extern C wrappers?
Thanks, Kris Walker

Accepted Answer

Vivek
Vivek on 2 Oct 2019
Hi,
We've introduced this capability in MATLAB starting in R2019a. Please take a look:

More Answers (2)

Guillaume
Guillaume on 23 Feb 2016
No, it's not going to happen. It's not possible.
It's not an issue specific to matlab. It's all to do with the fact that C++ does not have a standardised ABI. This means that in practice a C++ program (or dll) compiled with compiler A cannot talk to a C++ program (or dll) compiled with compiler B.
Even different versions of the same compiler, or different compilation switches with the same version are enough to break the ABI. If you try to call a C++ dll compiled with Visual Studio 12 from an executable compiled with Visual Studio 13, in all likelyhood it's going to crash. Particularly if you're using templates / exceptions / polymorphism / TMP and all the nice features of C++.
The whole purpose of the extern "C" wrappers is to make it possible for the programs to talk to each other.

Walter Roberson
Walter Roberson on 23 Feb 2016
No. Those are memory management contracts that conflict with MATLAB's memory management needs.

Community Treasure Hunt

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

Start Hunting!