This paper describes various approaches for calling shared libraries from Simulink models. Both explicit (load-time) and implicit (run-time) linking is considered.
Mikhail (2019). Calling Shared Libraries from Simulink (https://www.mathworks.com/matlabcentral/fileexchange/44197-calling-shared-libraries-from-simulink), MATLAB Central File Exchange. Retrieved .
Thanks, it works now
@Stephane You should use explicit linking (as opposed to implicit linking with import *.lib file). Manually written S-function (possibly combined with Legacy Code Tool to generate initial S-function) is the best approach. The article explains it all.
Your workflow invloves the lib file and not the dll file: how can I call a DLL file in Simulink (I have an header file but not the source code and not the lib file) ?
I've tried to use the legacy_code but if I replace the field HostLibFiles from exlib.lib to exlib.dll, when I run legacy_code('generate_for_sim',specs);, MATLAB says mex don't know dll
Easy to understand. Works really well.
@Alexandru, you can change the simulink preferences under (Preferences -> simulink -> Model file -> uncheck the "Do not load models created with a newer version of Simulink"), you will be able to open this in 2017b.
@Alexandru I'm keeping the models up to date with the current release of MATLAB. If you are using an older release, it is easy to reproduce the models - they are trivial (3 blocks) and screenshots are provided.
Any chance to have the submission also with 2017b?
@Jonathan you were probably using MinGW compiler. This should be addressed in the latest version of this submission.
The legacy_code method will also work for void-void functions without arguments.
I'm having problems replicating the "Manual 2-Level" method. Getting errors that the dllHandle, LoadLibrary are FreeLibrary functions are undeclared/unresolved when mex tries to link. Where are these defined in the sample code?.
Also, the legacy_code method I assume will only work properly if the core function uses arguments (i.e. to define at least one input and one output port) when the mexw32 is used in an s-FUNC?
I was wondering whether it is possible to call .dll created from simulink blocks with a Matlab executable. It seemed that one cannot do that since the sim command cannot be compiled into the MatLab executable. All the examples in this tutorial seemed to all require Simulink license to run.
To make S-functions work with Rapid Accelerator mode, you need to make them inline.
This is way beyond this article - either read the documentation or contact MathWorks Tech Support/Consulting for these issues.
Everything works so nice till we test in Accelerator mode. That means all mex works with the examples. But while we build or run in rapid accelerator mode all of them report Linker error. There seems to be some path issues or makefile problem. Your help is greatly appreciated if you can provide a fix for the same. Lot of people reported Linker error for Simulink builds with U1077, U1073.
Thanks in advance.
Great Tutorial, It's really helped me, Thanks.
how can i open these attachments ??
A good tutorial. Nice coverage of six (or seven) different ways to use c shared libraries in Simulink/Matlab.
Validated with R2019a
Fixed "MATLAB Function" model to work out of the box.
- Validated with R2018b
Update all models to R2017a;
Validated with MATLAB R2017a
Validated with MATLAB R2016b
Verify with 16a
Updated to R2015a, cosmetic changes.
This Toolbox checkbox keeps poping up
Add information about Embedded Coder
It's not a Toolbox. Very smart to have this checkbox ticked by default..
Add examples for MATLAB Function, MATLAB System, Stateflow
Add more clarifications and links, change wording, more items in TODO.