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

Hi
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 (<http://www.mathworks.com/matlabcentral/newsreader/view_thread/247302>)
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 (<http://www.mathworks.co.uk/help/toolbox/ecoder/ug/bq44n8v-mu.html#bq9240b-83mn>)
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,
Mohamad

 Accepted Answer

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.

3 Comments

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
Cheers
Mohamad
Thanks for taking the time to comment back, and let us know if you have success using rtwmakecfg.m.
I am having some trouble too. I wrote a mex file s-function and i want to use in simulink so i can run this in beaglebone black. However, i need to implement an external library that helps me and simulink is not recognizing this library. Every function that i call in my code returns "undefined reference to _____". How can i add flags in the external mode compiler? i think that is the problem.

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink Coder 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!