MATLAB Answers

Code generation for simulink model with C and C++ s-functions within

19 views (last 30 days)
I'm trying to generate code for a simulink mode which contains:
1- a C s-function
2- a C++ s-function
The generated code is expected to run on Linux and supports the External mode simulation
I kind of reached a dead-end and I want to make sure that what I did is correct:
1- a target preferences block is added to specify Linux OS and real-time scheduling properties. This will force an ide_link_ert target using C language
2- when I build the model, embedded coder skip all C++ source code files and hence my C++ s-functions causes an undefined reference error at the link stage.
3- compiling the whole project as C++ would solve it, but ide_link_ert doesn't support C++.
4- if I ignore the target preference block and set ert target with C++ language (just to see if it works) the build comes with lots of error messages complaining about type redefinition mismatch very similar to that the guy has got here (<>)
5- Thought about using referenced model for the C++ s-function so that the coder will generate a library file and link it with the rest of the generated C code. The problem with this approach is (<>)
a. Coder with referenced models doesn't support non-inlined s-functions (my C++ s-function is not inlined)
b. Coder with referenced model doesn't support the external mode, which I need
I appreciate if someone can point out if there is anything wrong with what is mentioned above or provide any inputs of how to solve this issue.
Kind regards,


Sign in to comment.

Accepted Answer

Rolfe Dlugy-Hegwer
Rolfe Dlugy-Hegwer on 6 Sep 2012
Hi Mohamad. A colleague of mine commented: [...] one way you could probably work around this is to pre-compile the C++ code into object files or a static library. From there, if you pair the ".mex" file with an "rtwmakecfg.m", you can add use the "rtwmakecfg.m" file to add the object/library files to the build.


MTA on 6 Sep 2012
Hi Rolfe
Thank you for your input. Actually today I was doing the same in a different approach. The coder puts all my C++ files in a SKIPPED_FILES variable in the generated makefile. I added a section under the prebuild target that will compile the SKIPPED_FILES into a shared library (.so) and used the linker options in the IDE link to add a linkage to that library.
The rtwmakecfg.m sounds interesting and less ad-hoc though, I might try it tomorrow
P.S. I must say the trick seems to work the compilation issues, and logically it shouldn't cause any problems. However I'm having problems with running the generated binary (killed by SIGRT) which I need to isolate before I say it's 100% safe
Rolfe Dlugy-Hegwer
Rolfe Dlugy-Hegwer on 7 Sep 2012
Thanks for taking the time to comment back, and let us know if you have success using rtwmakecfg.m.

Sign in to comment.

More Answers (0)