Compiling a C/C++ function with external dependencies

1 visualización (últimos 30 días)
Ryan
Ryan el 1 de Sept. de 2015
Respondida: Rutuja Shirali el 3 de Sept. de 2015
There is a cross-platform library called LCM, the lightweight communication and marshaling protocol, which provides some cool interprocess communication capabilities. I have C functions that can publish and subscribe to LCM channels. I want to get these functions into a Simulink block so that I can communicate with a running model from other processes. These functions, of course, have a dependency on the LCM library. I can compile this program in my C IDE with a cmakelists file - what is the most straightforward way to compile this program for Matlab?

Respuestas (1)

Rutuja Shirali
Rutuja Shirali el 3 de Sept. de 2015
Hi Ryan,
We can accomplish calling C/C++ code from MATLAB in the following ways:
  • We can directly call C library finctions from MATLAB by loading the library using the "loadlibrary" function and calling functions from the library using "calllib" function. More information about this can be found here:
  • Moreover, we can write a MEX-file to call C/C++ functions and then build it. While building we can use the "-L" and "-l" flags to specify external libraries. More information about MEX-file creation and the "mex" function can be found here:
I hope this helps with your issue. If this is not what you are expecting I would suggest contacting MathWorks Technical Support with more clarification on your workflow.
Thanks!
Rutuja

Categorías

Más información sobre Call C++ from MATLAB 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