Compiling a C/C++ function with external dependencies

조회 수: 3 (최근 30일)
Ryan
Ryan 2015년 9월 1일
답변: Rutuja Shirali 2015년 9월 3일
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에서 Simulink Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by