Problem with referenced models that contain calls to source code (accelerated mode)

3 views (last 30 days)
I have master model that contains a referenced model which invokes a callback function from external c-code via stateflow. What is not working is to simulate the master model in accelerated mode. Everything else works: - code generation to d-space target OK - Simulate normal mode OK - Simulate the referenced model OK I have put in the configuration parameters for the referenced model: Simulation target -> Header file: #include "CarCfgBits.h" Simulation target -> Source files: carCfgBits.c
Error message: Subsystemlib.lib(Subsystem.obj) : error LNK2019: unresolved external symbol extractCarCfgBits referenced in function Subsystem ..\..\..\Subsystem_msf.mexw64 : fatal error LNK1120: 1 unresolved externals
It does not seem that the source code is available (and including function extractCarCfgBits), when generating code for simulation target accelerated mode (for master model). Thus, the "refmodel_msf.mexw64" file can not be generated.
I attach a screenshot of how my test setup (minimized version) to reproduce the problem looks like.
Appreciate any feedback and hints here!

Answers (2)

Shivang Menon
Shivang Menon on 3 Nov 2016
Edited: Shivang Menon on 3 Nov 2016
I understand you are trying to include custom code in a stateflow chart and use that model as a reference model in a top model. However, running the parent model in accelerator results in linker errors.
I think the build should also fail if top model is in normal mode and you run the reference model block as accelerator.
This is an expected behaviour. The rationale is that it can cause inconsistencies between simulation and generated code in some cases. Consider the following example
A parent model and a child model, both containing Stateflow charts (though not necessarily the same Stateflow chart). Both models have the same source files listed in their custom code, and both Stateflow charts call a common function from custom code containing a global variable declared/defined in the custom code.
When generating code for the "final" build, (i.e. not the simulation target), the parent model's Stateflow chart and the child model's Stateflow chart will both call the same hand code function and use the same global variable.
In contrast, if we simulate with the child model in "accelerator mode", the results are quite different; The parent model's Stateflow chart uses a simulation target with the custom code compiled into it (including the global variable), but the child model uses its own separate simulation target that has a separate copy of the custom code (including the global variable).
This case wouldn't result in any sort of compilation/linking failure because the accelerated child model reference's simulation target is never linked with the parent model's. However, one case has two global variables while the other has only one, and their results are almost certain to differ.
Also, a stateflow chart is simply an S-function. So whatever limitations for model referencing apply to S-functions apply to stateflow charts as well. Refer to the following link for model referencing limitations in accelerator mode for S-functions:
Model Referencing Limitations : Refer to the Limitations on Accelerator Mode Referenced Models section.
The fact that the top model works while running in Rapid Accelerator mode is surprising - maybe you are invoking one of the S-function limitations from the above link for accelerator mode.
Hope this helps!

Anders Ekwall
Anders Ekwall on 7 Nov 2016
Thank you for the answer. I am able to simulate the parent model both in normal & rapid accelerator mode, but not in accelerator mode. Furthermore, I can simulate the referenced model in all modes(normal, accelerator, rapid accelerator). So basically the only thing that does not work is simulating the parent model in accelerator mode (which is the mode I need for the complete simulation with several different referenced models). I'm not sure what you mean with "In contrast, if we simulate with the child model in "accelerator mode"". Do you mean the referenced model as stand-alone here? Because when I change simulation to normal for the parent model, the simulation mode is changed to normal automatically for the referenced model.
Is the conclusion then that there is no work-around for this linker problem with custom code function calls in accelerated mode?
Again, thanks for you input!

Categories

Find more on Model References in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!