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

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Rolfe Dlugy-Hegwer
Rolfe Dlugy-Hegwer el 6 de Sept. de 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.
  3 comentarios
Rolfe Dlugy-Hegwer
Rolfe Dlugy-Hegwer el 7 de Sept. de 2012
Thanks for taking the time to comment back, and let us know if you have success using rtwmakecfg.m.
PEDRO HENRIQUE Ulhoa
PEDRO HENRIQUE Ulhoa el 21 de En. de 2021
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Simulink Coder en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by