How to run a C++ code in Matlab
156 次查看(过去 30 天)
显示 更早的评论
I have a code written in C++. How can I run this code in Matlab? Do I need to write some extra code to be able to run this code in matlab? Or do I need to change it completely? Thanks
0 个评论
回答(3 个)
KSSV
2016-2-22
You have to write wrappers. You must let MATLAB know that the code is c++; you have to write a code for input and output. The main code in c++ remains the same. You have to use mex compiler. You may read below documentation.
0 个评论
Walter Roberson
2016-2-22
It depends on the form of the C++ code. If it is compatible with being a shared object (such as being a DLL) then you can use loadlibrary() to attach to it, and calllib() to call into it, without needing to change the code. You would need a .h file (or equivalent) to use this.
In most operating systems and compilers, you would need special flags when compiling the C++ source to generate a shared object. In some operating systems, though, you could technically get away with just a normal compile (but you would probably routinely include some special flags for the task anyhow so that you create a better shared object.)
0 个评论
Kestas Subacius
2020-1-13
We've introduced the capability to call C++ libraries directly from MATLAB as of R2019a. Please take a look:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 C Shared Library Integration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!