How to run a C++ code in Matlab

187 visualizaciones (últimos 30 días)
MINA
MINA el 22 de Feb. de 2016
Respondida: Kestas Subacius el 13 de En. de 2020
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

Respuestas (3)

KSSV
KSSV el 22 de Feb. de 2016
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.

Walter Roberson
Walter Roberson el 22 de Feb. de 2016
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.)

Kestas Subacius
Kestas Subacius el 13 de En. de 2020
We've introduced the capability to call C++ libraries directly from MATLAB as of R2019a. Please take a look:

Categorías

Más información sobre Build MATLAB Interface to C++ Library en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by