Compiling a C/C++ function with external dependencies

4 views (last 30 days)
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?

Answers (1)

Rutuja Shirali
Rutuja Shirali on 3 Sep 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

Community Treasure Hunt

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

Start Hunting!