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

조회 수: 2 (최근 30일)
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

채택된 답변

Rolfe Dlugy-Hegwer
Rolfe Dlugy-Hegwer 2012년 9월 6일
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
Rolfe Dlugy-Hegwer
Rolfe Dlugy-Hegwer 2012년 9월 7일
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 2021년 1월 21일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by