MATLAB Answers


How do I create stub functions in simulink for legacy code?

Asked by Nathan Crosty on 15 Aug 2013

I would like to use sfunctions to create function calls to a external c functions. I don't want to build the actual legacy code when I try to build the model, but I would rather just create stub functions. What is the best way to accomplish this?

I have created stub.h./stub.c files with empty function calls (with the actual function call names), and then generated the sfunctions with the legacy code tool, but of course the autocoder includes stub.h. Rather than stub.h, I would rather include the actual .h file that is the true header file.

Thank you for and advice.


1 Answer

Answer by Kaustubha Govind
on 16 Aug 2013

I think the right way to do what you want to achieve is to create a DLL for your external C-functions and load it dynamically from the S-function. Note that the interface to the functions still needs to be fully specified in the header file and if changed needs the S-function to be re-compiled. However, using a DLL allows you to compile/maintain your external C code independently from the S-function.


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!