call C++ from Matalb
5 views (last 30 days)
Show older comments
Dear technical support
I want to call a function written in c++ from Matlab, but do not have an idea how to do it.
I wrote a c++ function which is dependent on an open c++ library (Point cloud library (PCL)), and now I need to use this function in Matlab.
I read the example here: https://au.mathworks.com/help/matlab/matlab_external/standalone-example.html
This example looks good, but it does not show how to link another c++ library like PCL, which is what I need.
Another example shows how to call a c function. https://au.mathworks.com/help/matlab/ref/loadlibrary.html
But I don’t know how to make it work for me. Do I need firstly convert my c++ function to a static library and then use the loadlibrary function?
Thank you for your help!
Regards!
Huajian liu
0 Comments
Answers (4)
Vivek
on 2 Oct 2019
We've introduced this capability in MATLAB starting in R2019a. Please take a look:
0 Comments
Walter Roberson
on 15 Jun 2017
You do not need to use a static library. However, you need to build a C-compatible interface to the library. It is not possible for MATLAB to call into a C++ object member function: it can only call into C++ static functions and static class functions that defined with
extern "C"
It is, however, possible for a call to a static class function to return an opaque pointer to a C++ object as long as it converts it using (void *) and the MATLAB routine does not do any calculation on it.
0 Comments
HANS
on 19 Mar 2018
Hi to all :)
I have name.mex function and many .cpp and .h files related to it. name.mex takes only 1xinf vector which is a complex double values inside and output is the same size vector.
I want to call this name.mex within C++. As I know I have to use "int mexCallMATLAB(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[], const char *command_name);"
Please could anybody give a usage example in C++ ? I guess I have to use "ifstream" to load the data vector before I use the function but do I have to define via "mxArray" or ??
Thx, WR
0 Comments
See Also
Categories
Find more on Call C++ from MATLAB 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!