Compiling a C/C++ function with external dependencies

3 次查看(过去 30 天)
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?

回答(1 个)

Rutuja Shirali
Rutuja Shirali 2015-9-3
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

类别

Help CenterFile Exchange 中查找有关 Call C++ from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by